In C, 'extern' is typically used to avoid tentative definitions when declaring variables in headers, but adding an intializer makes it a defintion. This is somewhat confusing, so GCC and Clang both warn on it. In C++, 'extern' is often used to give implictly static 'const' variables external linkage, so don't warn in that case. If selectany is present, this might be header code intended for C and C++ inclusion, so apply the C++ rules. llvm-svn: 279116
9 lines
426 B
C
9 lines
426 B
C
// RUN: %clang_cc1 -fms-compatibility -fms-extensions -verify %s
|
|
|
|
extern __declspec(selectany) const int x1 = 1; // no warning, const means we need extern in C++
|
|
|
|
// Should we really warn on this?
|
|
extern __declspec(selectany) int x2 = 1; // expected-warning {{'extern' variable has an initializer}}
|
|
|
|
__declspec(selectany) void foo() { } // expected-error{{'selectany' can only be applied to data items with external linkage}}
|