r209996 - Fix the undefined-but-used odr-use marker (DR48)

Alp Toker alp at nuanti.com
Sun Jun 1 11:49:32 PDT 2014


Author: alp
Date: Sun Jun  1 13:49:32 2014
New Revision: 209996

URL: http://llvm.org/viewvc/llvm-project?rev=209996&view=rev
Log:
Fix the undefined-but-used odr-use marker (DR48)

We should treat tentative definitions as undefined for the purpose of
ODR-use linkage checking.

This broke somewhere around r149731 when tests were disabled.

Note that test coverage for these diagnostics is generally lacking due to a
separate issue (PR19910: Don't suppress unused/undefined warnings when there
are errors).

Modified:
    cfe/trunk/include/clang/Sema/SemaInternal.h
    cfe/trunk/test/CXX/drs/dr0xx.cpp
    cfe/trunk/test/SemaCXX/undefined-internal.cpp

Modified: cfe/trunk/include/clang/Sema/SemaInternal.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/SemaInternal.h?rev=209996&r1=209995&r2=209996&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/SemaInternal.h (original)
+++ cfe/trunk/include/clang/Sema/SemaInternal.h Sun Jun  1 13:49:32 2014
@@ -58,10 +58,8 @@ inline void MarkVarDeclODRUsed(VarDecl *
     SourceLocation Loc, Sema &SemaRef,
     const unsigned *const FunctionScopeIndexToStopAt) {
   // Keep track of used but undefined variables.
-  // FIXME: We shouldn't suppress this warning for static data members.
-  if (Var->hasDefinition(SemaRef.Context) == VarDecl::DeclarationOnly &&
-    !Var->isExternallyVisible() &&
-    !(Var->isStaticDataMember() && Var->hasInit())) {
+  if (Var->hasDefinition(SemaRef.Context) != VarDecl::Definition &&
+      !Var->isExternallyVisible()) {
       SourceLocation &old = SemaRef.UndefinedButUsed[Var->getCanonicalDecl()];
       if (old.isInvalid()) old = Loc;
   }

Modified: cfe/trunk/test/CXX/drs/dr0xx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr0xx.cpp?rev=209996&r1=209995&r2=209996&view=diff
==============================================================================
--- cfe/trunk/test/CXX/drs/dr0xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr0xx.cpp Sun Jun  1 13:49:32 2014
@@ -507,14 +507,13 @@ namespace dr48 { // dr48: yes
   namespace {
     struct S {
       static const int m = 0;
-      static const int n = 0;
+      // FIXME: This diagnostic is working but gets suppressed due to other errors in the TU.
+      static const int n = 0; // FIXME-expected-warning {{has internal linkage but is not defined}}
       static const int o = 0;
     };
   }
   int a = S::m;
-  // FIXME: We should produce a 'has internal linkage but is not defined'
-  // diagnostic for 'S::n'.
-  const int &b = S::n;
+  const int &b = S::n; // FIXME-expected-note {{used here}}
   const int S::o;
   const int &c = S::o;
 }

Modified: cfe/trunk/test/SemaCXX/undefined-internal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/undefined-internal.cpp?rev=209996&r1=209995&r2=209996&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/undefined-internal.cpp (original)
+++ cfe/trunk/test/SemaCXX/undefined-internal.cpp Sun Jun  1 13:49:32 2014
@@ -137,15 +137,12 @@ namespace cxx11_odr_rules {
   //
   // Note that the warning in question can trigger in cases some people would
   // consider false positives; hopefully that happens rarely in practice.
-  //
-  // FIXME: Suppressing this test while I figure out how to fix a bug in the
-  // odr-use marking code.
 
   namespace {
     struct A {
       static const int unused = 10;
-      static const int used1 = 20; // xpected-warning {{internal linkage}}
-      static const int used2 = 20; // xpected-warning {{internal linkage}}
+      static const int used1 = 20; // expected-warning {{internal linkage}}
+      static const int used2 = 20; // expected-warning {{internal linkage}}
       virtual ~A() {}
     };
   }
@@ -166,10 +163,10 @@ namespace cxx11_odr_rules {
 
     // Check that the checks work with unevaluated contexts
     (void)sizeof(p(A::used1));
-    (void)typeid(p(A::used1)); // xpected-note {{used here}}
+    (void)typeid(p(A::used1)); // expected-note {{used here}}
 
     // Misc other testing
-    a(A::unused, 1 ? A::used2 : A::used2); // xpected-note {{used here}}
+    a(A::unused, 1 ? A::used2 : A::used2); // expected-note {{used here}}
     b();
   }
 }





More information about the cfe-commits mailing list