]> granicus.if.org Git - clang/commitdiff
Don't warn about static const integral data members with in-line constant
authorJohn McCall <rjmccall@apple.com>
Mon, 21 Feb 2011 19:25:48 +0000 (19:25 +0000)
committerJohn McCall <rjmccall@apple.com>
Mon, 21 Feb 2011 19:25:48 +0000 (19:25 +0000)
initializers just because they don't have a proper out-of-line definition.
Such code is technically ill-formed but is too common and too unlikely to be
a problem to be seriously worth worrying about.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126137 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/undefined-internal.cpp

index 84baa7d98525b2ee096d6a4339909b692fbae2f9..e7d167ed387e066a93b1d33988be82545870e997 100644 (file)
@@ -9336,9 +9336,12 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) {
       }
     }
 
-    // Keep track of used but undefined variables.
+    // Keep track of used but undefined variables.  We make a hole in
+    // the warning for static const data members with in-line
+    // initializers.
     if (Var->hasDefinition() == VarDecl::DeclarationOnly
-        && Var->getLinkage() != ExternalLinkage) {
+        && Var->getLinkage() != ExternalLinkage
+        && !(Var->isStaticDataMember() && Var->hasInit())) {
       SourceLocation &old = UndefinedInternals[Var->getCanonicalDecl()];
       if (old.isInvalid()) old = Loc;
     }
index bb87ce0f126cc402e89f5194b9a4bf243f18d5da..a7e924996574dbe883c4aec13a48949cf8966aed 100644 (file)
@@ -84,3 +84,24 @@ namespace test5 {
     B<A>::foo(); // expected-note {{used here}}
   }
 }
+
+namespace test6 {
+  template <class T> struct A {
+    static const int zero = 0;
+    static const int one = 1;
+    static const int two = 2;
+
+    int value;
+
+    A() : value(zero) {
+      value = one;
+    }
+  };
+
+  namespace { struct Internal; }
+
+  void test() {
+    A<Internal> a;
+    a.value = A<Internal>::two;
+  }
+}