You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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$ ../../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.
The text was updated successfully, but these errors were encountered:
How about "don't use -nobuiltininc" instead? We are never going to support MSVC's stdarg.h, and given that, we really just need to make our builtin includes either work or forward appropriately.
Sorry, I'm not prepared to break the constant expression code this much. Accepting (say) reinterpret_casts of null pointers is far from enough to get this treated as a constant expression. "((S*)0)->m" isn't allowed in a constant expression, because you can't access members of null pointers in a constant expression. And the cast from void* to long isn't allowed in a constant expression either.
However, the expression is foldable. If Eli's suggestion is unworkable for some reason and you really need this code pattern to compile, I think it'd be acceptable to make either -fms-extensions or -fms-compatibility allow constant folding in non-type template arguments.
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.
The text was updated successfully, but these errors were encountered: