Provide better diagnostic wording for initializers on static
data member definitions when the variable has an initializer
in its declaration.
For the following code:
struct S {
static const int x = 42;
};
const int S::x = 42;
This patch changes the diagnostic from:
a.cc:4:14: error: redefinition of 'x'
const int S::x = 42;
^
a.cc:2:20: note: previous definition is here
static const int x = 42;
^
to:
a.cc:4:18: error: static data member 'x' already has an initializer
const int S::x = 42;
^
a.cc:2:24: note: previous initialization is here
static const int x = 42;
^
Differential Revision: http://llvm-reviews.chandlerc.com/D2235
llvm-svn: 195306
diff --git a/clang/test/CXX/class/class.static/class.static.data/p4.cpp b/clang/test/CXX/class/class.static/class.static.data/p4.cpp
index 2b1eca7..85d18c6 100644
--- a/clang/test/CXX/class/class.static/class.static.data/p4.cpp
+++ b/clang/test/CXX/class/class.static/class.static.data/p4.cpp
@@ -10,15 +10,14 @@
int const OutOfClassInitializerOnly::i = 0;
struct InClassInitializerAndOutOfClassCopyInitializer {
- static const int i = 0; // expected-note{{previous definition is here}}
+ static const int i = 0; // expected-note{{previous initialization is here}}
};
-int const InClassInitializerAndOutOfClassCopyInitializer::i = 0; // expected-error{{redefinition of 'i'}}
+int const InClassInitializerAndOutOfClassCopyInitializer::i = 0; // expected-error{{static data member 'i' already has an initializer}}
struct InClassInitializerAndOutOfClassDirectInitializer {
- static const int i = 0; // expected-note{{previous definition is here}}
+ static const int i = 0; // expected-note{{previous initialization is here}}
};
-int const InClassInitializerAndOutOfClassDirectInitializer::i(0); // expected-error{{redefinition of 'i'}}
-
+int const InClassInitializerAndOutOfClassDirectInitializer::i(0); // expected-error{{static data member 'i' already has an initializer}}
int main() { }
diff --git a/clang/test/CXX/drs/dr0xx.cpp b/clang/test/CXX/drs/dr0xx.cpp
index 265a52d..57e3a75 100644
--- a/clang/test/CXX/drs/dr0xx.cpp
+++ b/clang/test/CXX/drs/dr0xx.cpp
@@ -919,11 +919,10 @@
namespace dr88 { // dr88: yes
template<typename T> struct S {
- static const int a = 1;
+ static const int a = 1; // expected-note {{previous}}
static const int b;
};
- // FIXME: This diagnostic is pretty bad.
- template<> const int S<int>::a = 4; // expected-error {{redefinition}} expected-note {{previous}}
+ template<> const int S<int>::a = 4; // expected-error {{already has an initializer}}
template<> const int S<int>::b = 4;
}