Skip to content

Commit 6935e90

Browse files
committed
Use tag name lookup for class names
This PR would fix #16855 . I think the correct lookup to use for class names is Tag name lookup, because it does not take namespaces into account. The current lookup does and because of this some valid programs are not accepted. If you think that Tag name lookup is not correct for all cases when we are looking up types based on class names then we can only do tag name lookup when looking up class names for inheritance. In case of inheritance: ``` [class.derived]p2 says: "During the lookup for a base class name, non-type names are ignored." ```
1 parent 36a4055 commit 6935e90

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ Bug Fixes to C++ Support
513513
- Clang no longer crashes when a lambda contains an invalid block declaration that contains an unexpanded
514514
parameter pack. (#GH109148)
515515
- Fixed overload handling for object parameters with top-level cv-qualifiers in explicit member functions (#GH100394)
516+
- During the lookup for a base class name, non-type names are ignored. (#GH16855)
516517

517518
Bug Fixes to AST Handling
518519
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDecl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,13 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
357357
return nullptr;
358358
}
359359

360-
// FIXME: LookupNestedNameSpecifierName isn't the right kind of
361-
// lookup for class-names.
362-
LookupNameKind Kind = isClassName ? LookupNestedNameSpecifierName :
363-
LookupOrdinaryName;
360+
// In the case where we know that the identifier is a class name, we know that
361+
// it is a type declaration (struct, class, union or enum) so we can use tag
362+
// name lookup.
363+
//
364+
// C++ [class.derived]p2 (wrt lookup in a base-specifier): The lookup for
365+
// the component name of the type-name or simple-template-id is type-only.
366+
LookupNameKind Kind = isClassName ? LookupTagName : LookupOrdinaryName;
364367
LookupResult Result(*this, &II, NameLoc, Kind);
365368
if (LookupCtx) {
366369
// Perform "qualified" name lookup into the declaration context we

clang/test/CXX/class.derived/p2.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,16 @@ namespace PR5840 {
66
struct Base {};
77
int Base = 10;
88
struct Derived : Base {};
9-
}
9+
} // namespace PR5840
10+
11+
namespace issue_16855 {
12+
struct x {};
13+
namespace
14+
{
15+
namespace x
16+
{
17+
struct y : x
18+
{};
19+
} // namespace x
20+
}
21+
} // namespace issue_16855

0 commit comments

Comments
 (0)