Skip to content

Allow reinterpret_cast in constant expressions in microsoft mode #12488

Description

@nico
Bugzilla Link 12116
Resolution WONTFIX
Resolved on Aug 29, 2018 10:24
Version unspecified
OS All
Blocks llvm/llvm-bugzilla-archive#12477
CC @DougGregor,@efriedma-quic,@tritao,@zygoloid

Extended Description

When compiling ms headers with -nobuiltininc, clang picks up offsetof() from msvc's stddef.h ( http://msdn.microsoft.com/en-us/library/dz4y9b9a(v=vs.80).aspx ). If it's used with chrome's STATIC_ASSERT macro, clang complains about "reinterpret_cast not allowed in constant expressions".

I came up with an offsetof() macro that exhibits the same error:

hummer:clang thakis$ cat test.cc
#define offsetof(s,m)
(long)(void*)&((reinterpret_cast<s*>(0)->m))

template
struct GpuCompileAssert {
};

struct SetToken {
int a, token;
};

GpuCompileAssert<(bool(offsetof(SetToken, token) == 4))> foo;

hummer:clang thakis$ ../../Release+Asserts/bin/clang -c test.cc -fms-extensions -fms-compatibility
here4!
here3!
test.cc:12:18: error: non-type template argument of type 'bool' is not an integral constant expression
GpuCompileAssert<(bool(offsetof(SetToken, token) == 4))> foo;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cc:12:24: note: cast which performs the conversions of a reinterpret_cast is not allowed in a constant expression
GpuCompileAssert<(bool(offsetof(SetToken, token) == 4))> foo;
^
test.cc:2:3: note: expanded from macro 'offsetof'
(long)(void*)&((reinterpret_cast<s*>(0)->m))
^
1 error generated.

We should allow reinterpret_cast<>()s in constant expressions in microsoft mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++wontfixIssue is real, but we can't or won't fix it. Not invalid

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions