r216628 - PR20769: Fix confusion when checking whether a prior default argument was in

Richard Smith richard-llvm at metafoo.co.uk
Wed Aug 27 15:31:35 PDT 2014


Author: rsmith
Date: Wed Aug 27 17:31:34 2014
New Revision: 216628

URL: http://llvm.org/viewvc/llvm-project?rev=216628&view=rev
Log:
PR20769: Fix confusion when checking whether a prior default argument was in
scope when checking for conflicts.

Modified:
    cfe/trunk/lib/Sema/IdentifierResolver.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/default1.cpp

Modified: cfe/trunk/lib/Sema/IdentifierResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/IdentifierResolver.cpp?rev=216628&r1=216627&r2=216628&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/IdentifierResolver.cpp (original)
+++ cfe/trunk/lib/Sema/IdentifierResolver.cpp Wed Aug 27 17:31:34 2014
@@ -130,6 +130,9 @@ bool IdentifierResolver::isDeclInScope(D
     return false;
   }
 
+  // FIXME: If D is a local extern declaration, this check doesn't make sense;
+  // we should be checking its lexical context instead in that case, because
+  // that is its scope.
   DeclContext *DCtx = D->getDeclContext()->getRedeclContext();
   return AllowInlineNamespace ? Ctx->InEnclosingNamespaceSetOf(DCtx)
                               : Ctx->Equals(DCtx);

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=216628&r1=216627&r2=216628&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Aug 27 17:31:34 2014
@@ -446,20 +446,24 @@ bool Sema::MergeCXXFunctionDecl(Function
     bool OldParamHasDfl = OldParam->hasDefaultArg();
     bool NewParamHasDfl = NewParam->hasDefaultArg();
 
-    NamedDecl *ND = Old;
-
     // The declaration context corresponding to the scope is the semantic
     // parent, unless this is a local function declaration, in which case
     // it is that surrounding function.
-    DeclContext *ScopeDC = New->getLexicalDeclContext();
-    if (!ScopeDC->isFunctionOrMethod())
-      ScopeDC = New->getDeclContext();
-    if (S && !isDeclInScope(ND, ScopeDC, S) &&
+    DeclContext *ScopeDC = New->isLocalExternDecl()
+                               ? New->getLexicalDeclContext()
+                               : New->getDeclContext();
+    if (S && !isDeclInScope(Old, ScopeDC, S) &&
         !New->getDeclContext()->isRecord())
       // Ignore default parameters of old decl if they are not in
       // the same scope and this is not an out-of-line definition of
       // a member function.
       OldParamHasDfl = false;
+    if (New->isLocalExternDecl() != Old->isLocalExternDecl())
+      // If only one of these is a local function declaration, then they are
+      // declared in different scopes, even though isDeclInScope may think
+      // they're in the same scope. (If both are local, the scope check is
+      // sufficent, and if neither is local, then they are in the same scope.)
+      OldParamHasDfl = false;
 
     if (OldParamHasDfl && NewParamHasDfl) {
 

Modified: cfe/trunk/test/SemaCXX/default1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/default1.cpp?rev=216628&r1=216627&r2=216628&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/default1.cpp (original)
+++ cfe/trunk/test/SemaCXX/default1.cpp Wed Aug 27 17:31:34 2014
@@ -65,3 +65,9 @@ int i2() {
 
 int pr20055_f(int x = 0, int y = UNDEFINED); // expected-error{{use of undeclared identifier}}
 int pr20055_v = pr20055_f(0);
+
+void PR20769() { void PR20769(int = 1); }
+void PR20769(int = 2);
+
+void PR20769_b(int = 1);
+void PR20769_b() { void PR20769_b(int = 2); }





More information about the cfe-commits mailing list