r252125 - [modules] Don't merge an anonymous enum definition into a named enum definition.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 17:30:19 PST 2015


Author: rsmith
Date: Wed Nov  4 19:30:19 2015
New Revision: 252125

URL: http://llvm.org/viewvc/llvm-project?rev=252125&view=rev
Log:
[modules] Don't merge an anonymous enum definition into a named enum definition.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Modules/merge-enumerators.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=252125&r1=252124&r2=252125&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Nov  4 19:30:19 2015
@@ -13900,10 +13900,12 @@ Sema::SkipBodyInfo Sema::shouldSkipAnonE
   NamedDecl *PrevDecl = LookupSingleName(S, II, IILoc, LookupOrdinaryName,
                                          ForRedeclaration);
   auto *PrevECD = dyn_cast_or_null<EnumConstantDecl>(PrevDecl);
+  if (!PrevECD)
+    return SkipBodyInfo();
+
+  EnumDecl *PrevED = cast<EnumDecl>(PrevECD->getDeclContext());
   NamedDecl *Hidden;
-  if (PrevECD &&
-      !hasVisibleDefinition(cast<NamedDecl>(PrevECD->getDeclContext()),
-                            &Hidden)) {
+  if (!PrevED->getDeclName() && !hasVisibleDefinition(PrevED, &Hidden)) {
     SkipBodyInfo Skip;
     Skip.Previous = Hidden;
     return Skip;

Modified: cfe/trunk/test/Modules/merge-enumerators.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-enumerators.cpp?rev=252125&r1=252124&r2=252125&view=diff
==============================================================================
--- cfe/trunk/test/Modules/merge-enumerators.cpp (original)
+++ cfe/trunk/test/Modules/merge-enumerators.cpp Wed Nov  4 19:30:19 2015
@@ -4,8 +4,23 @@
 // RUN: echo '#include "a.h"' > %t/b.h
 // RUN: touch %t/x.h
 // RUN: echo 'module B { module b { header "b.h" } module x { header "x.h" } }' > %t/b.modulemap
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x c++ -fmodule-map-file=%t/b.modulemap %s -I%t -verify
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x c++ -fmodule-map-file=%t/b.modulemap %s -I%t -verify -fmodules-local-submodule-visibility
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x c++ -fmodule-map-file=%t/b.modulemap %s -I%t -verify -fmodules-local-submodule-visibility -DMERGE_LATE
+
+#ifndef MERGE_LATE
 // expected-no-diagnostics
 #include "a.h"
+#endif
+
 #include "x.h"
+
+#ifdef MERGE_LATE
+namespace N {
+  // FIXME: Should we accept this and reject the usage below due to ambiguity instead?
+  enum { A } a; // expected-error {{redefinition of enumerator 'A'}}
+  // expected-note at a.h:1 {{here}} (from module B.b)
+}
+#include "a.h"
+#endif
+
 N::E e = N::A;




More information about the cfe-commits mailing list