]> granicus.if.org Git - clang/commitdiff
[modules] Don't merge an anonymous enum definition into a named enum definition.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 5 Nov 2015 01:30:19 +0000 (01:30 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 5 Nov 2015 01:30:19 +0000 (01:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252125 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Modules/merge-enumerators.cpp

index b14109a6d79e727f1a70bb78a1e4014e77fcdf64..6297efb73a20bc43547764c22f37f1c54d6f63d6 100644 (file)
@@ -13900,10 +13900,12 @@ Sema::SkipBodyInfo Sema::shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II,
   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;
index 34a4ec9523fa2a6c5a4ca9333bd075fc3bffe725..5267ac658b8be1a913a2e81d860aa375cc49fd8c 100644 (file)
@@ -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@a.h:1 {{here}} (from module B.b)
+}
+#include "a.h"
+#endif
+
 N::E e = N::A;