llvm / llvm/llvm-project

[Clang] `alignof(nullptr_t)` is inconsistent with MSVC when using MSVC ABI

Open
#183,670 2 comments 1 reaction 0 assignees View on GitHub
ABI clang:codegen clang:frontend diverges-from:msvc platform:windows
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Currently, Clang sets `alignof(nullptr_t)` equal to `alignof(void*)` when using MSVC ABI, but MSVC sets `alignof(nullptr_t)` to 1. [Godbolt link](https://godbolt.org/z/qj6TPWf3v). It seems that if one explicitly uses `alignof(nullptr_t)` or `alignas(nullptr_t)`, there would be source and/or ABI incompatibility with MSVC.

I think Clang's behavior is desired and consistent with C23 requirements (see also [CWG2966](https://cplusplus.github.io/CWG/issues/2966.html)). Also, MSVC seemingly treats `nullptr_t` as something aligned as `void*` when calculating class layout, which is a bit weird.

Do we want to get closer to MSVC or inform MSVC to change?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the alignment difference using the linked Godbolt example, then read CWG2966 and compare the reported Clang and MSVC behavior. Done requires a project decision on whether Clang should preserve its current behavior, change toward MSVC, or pursue coordination with MSVC; the issue does not identify implementation files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.