Skip to content

Commit

Permalink
[MS] Fix assert handling enum forward decls in hasVisibleDefinition
Browse files Browse the repository at this point in the history
An enum may be considered to be a complete type if it was forward
declared. It may be declared with a fixed underlying type, or, in MSVC
compatiblity mode, with no type at all.

Previously, the code was written with special handling for fixed enums.
I generalized the code to check if the underlying integer type is known,
which should be the case when targetting the MSVC C++ ABI.

Fixes PR45409
  • Loading branch information
rnk committed Apr 3, 2020
1 parent 98f7782 commit e62dc1f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions clang/lib/Sema/SemaType.cpp
Expand Up @@ -8060,10 +8060,10 @@ bool Sema::hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested,
} else if (auto *ED = dyn_cast<EnumDecl>(D)) {
if (auto *Pattern = ED->getTemplateInstantiationPattern())
ED = Pattern;
if (OnlyNeedComplete && ED->isFixed()) {
// If the enum has a fixed underlying type, and we're only looking for a
// complete type (not a definition), any visible declaration of it will
// do.
if (OnlyNeedComplete && !ED->getIntegerType().isNull()) {
// If the enum has an integer type, it may have been forward declared.
// Since we're only looking for a complete type (not a definition), any
// visible declaration of it will do.
*Suggested = nullptr;
for (auto *Redecl : ED->redecls()) {
if (isVisible(Redecl))
Expand Down
1 change: 1 addition & 0 deletions clang/test/Modules/Inputs/ms-enums/A.h
@@ -0,0 +1 @@
enum fwd_enum;
1 change: 1 addition & 0 deletions clang/test/Modules/Inputs/ms-enums/B.h
@@ -0,0 +1 @@
#include "A.h"
2 changes: 2 additions & 0 deletions clang/test/Modules/Inputs/ms-enums/module.map
@@ -0,0 +1,2 @@
module A { header "A.h" }
module B { header "B.h" }
12 changes: 12 additions & 0 deletions clang/test/Modules/ms-enums.cpp
@@ -0,0 +1,12 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -fms-compatibility -x c++ -std=c++20 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/ms-enums %s -verify -fno-modules-error-recovery

#include "B.h"
// expected-note@A.h:1 {{previous declaration is here}}
// expected-note@A.h:1 2 {{previous definition is here}}

fwd_enum gv_enum; // expected-error {{must be imported}}

struct Foo {
enum fwd_enum enum_field; // expected-error 2 {{must be imported}}
};

0 comments on commit e62dc1f

Please sign in to comment.