summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp8
-rw-r--r--clang/test/Modules/merge-enumerators.cpp17
2 files changed, 21 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b14109a6d79..6297efb73a2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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;
diff --git a/clang/test/Modules/merge-enumerators.cpp b/clang/test/Modules/merge-enumerators.cpp
index 34a4ec9523f..5267ac658b8 100644
--- a/clang/test/Modules/merge-enumerators.cpp
+++ b/clang/test/Modules/merge-enumerators.cpp
@@ -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;
OpenPOWER on IntegriCloud