[cfe-commits] r126137 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/undefined-internal.cpp

John McCall rjmccall at apple.com
Mon Feb 21 11:25:49 PST 2011


Author: rjmccall
Date: Mon Feb 21 13:25:48 2011
New Revision: 126137

URL: http://llvm.org/viewvc/llvm-project?rev=126137&view=rev
Log:
Don't warn about static const integral data members with in-line constant
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.


Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/undefined-internal.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=126137&r1=126136&r2=126137&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Feb 21 13:25:48 2011
@@ -9336,9 +9336,12 @@
       }
     }
 
-    // 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;
     }

Modified: cfe/trunk/test/SemaCXX/undefined-internal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/undefined-internal.cpp?rev=126137&r1=126136&r2=126137&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/undefined-internal.cpp (original)
+++ cfe/trunk/test/SemaCXX/undefined-internal.cpp Mon Feb 21 13:25:48 2011
@@ -84,3 +84,24 @@
     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;
+  }
+}





More information about the cfe-commits mailing list