Skip to content

Commit 60809cd

Browse files
committed
Revert "[clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access"
This reverts commit dc17043. Breaks building LLVM on mac when targeting macOS before 10.15, see comments on https://reviews.llvm.org/D136533
1 parent 9d5adc7 commit 60809cd

File tree

6 files changed

+33
-64
lines changed

6 files changed

+33
-64
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ Bug Fixes
255255
- Reject non-type template arguments formed by casting a non-zero integer
256256
to a pointer in pre-C++17 modes, instead of treating them as null
257257
pointers.
258-
- Fix missing diagnostics for uses of declarations when performing typename access,
259-
such as when performing member access on a '[[deprecated]]' type alias.
260-
`Issue 58547 <https://github.com/llvm/llvm-project/issues/58547>`
261258

262259
Improvements to Clang's diagnostics
263260
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,10 +2566,6 @@ class Sema final {
25662566

25672567
bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
25682568

2569-
enum class DiagCtorKind { None, Implicit, Typename };
2570-
QualType getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
2571-
TypeDecl *TD, SourceLocation NameLoc);
2572-
25732569
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
25742570
Scope *S, CXXScopeSpec *SS = nullptr,
25752571
bool isClassName = false, bool HasTrailingDot = false,

clang/lib/Sema/SemaDecl.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,6 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const {
169169
return false;
170170
}
171171

172-
QualType Sema::getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
173-
TypeDecl *TD, SourceLocation NameLoc) {
174-
auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
175-
auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
176-
if (DCK != DiagCtorKind::None && LookupRD && FoundRD &&
177-
FoundRD->isInjectedClassName() &&
178-
declaresSameEntity(LookupRD, cast<Decl>(FoundRD->getParent()))) {
179-
Diag(NameLoc,
180-
DCK == DiagCtorKind::Typename
181-
? diag::ext_out_of_line_qualified_id_type_names_constructor
182-
: diag::err_out_of_line_qualified_id_type_names_constructor)
183-
<< TD->getIdentifier() << /*Type*/ 1
184-
<< 0 /*if any keyword was present, it was 'typename'*/;
185-
}
186-
187-
DiagnoseUseOfDecl(TD, NameLoc);
188-
MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
189-
return Context.getTypeDeclType(TD);
190-
}
191-
192172
namespace {
193173
enum class UnqualifiedTypeNameLookupResult {
194174
NotFound,
@@ -352,11 +332,10 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
352332
bool IsClassTemplateDeductionContext,
353333
ImplicitTypenameContext AllowImplicitTypename,
354334
IdentifierInfo **CorrectedII) {
355-
bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
356335
// FIXME: Consider allowing this outside C++1z mode as an extension.
357336
bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
358-
getLangOpts().CPlusPlus17 && IsImplicitTypename &&
359-
!HasTrailingDot;
337+
getLangOpts().CPlusPlus17 && !IsCtorOrDtorName &&
338+
!isClassName && !HasTrailingDot;
360339

361340
// Determine where we will perform name lookup.
362341
DeclContext *LookupCtx = nullptr;
@@ -380,9 +359,11 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
380359
// refer to a member of an unknown specialization.
381360
// In C++2a, in several contexts a 'typename' is not required. Also
382361
// allow this as an extension.
362+
if (AllowImplicitTypename == ImplicitTypenameContext::No &&
363+
!isClassName && !IsCtorOrDtorName)
364+
return nullptr;
365+
bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
383366
if (IsImplicitTypename) {
384-
if (AllowImplicitTypename == ImplicitTypenameContext::No)
385-
return nullptr;
386367
SourceLocation QualifiedLoc = SS->getRange().getBegin();
387368
if (getLangOpts().CPlusPlus20)
388369
Diag(QualifiedLoc, diag::warn_cxx17_compat_implicit_typename);
@@ -556,10 +537,18 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
556537
// C++ [class.qual]p2: A lookup that would find the injected-class-name
557538
// instead names the constructors of the class, except when naming a class.
558539
// This is ill-formed when we're not actually forming a ctor or dtor name.
559-
T = getTypeDeclType(LookupCtx,
560-
IsImplicitTypename ? DiagCtorKind::Implicit
561-
: DiagCtorKind::None,
562-
TD, NameLoc);
540+
auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
541+
auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
542+
if (!isClassName && !IsCtorOrDtorName && LookupRD && FoundRD &&
543+
FoundRD->isInjectedClassName() &&
544+
declaresSameEntity(LookupRD, cast<Decl>(FoundRD->getParent())))
545+
Diag(NameLoc, diag::err_out_of_line_qualified_id_type_names_constructor)
546+
<< &II << /*Type*/1;
547+
548+
DiagnoseUseOfDecl(IIDecl, NameLoc);
549+
550+
T = Context.getTypeDeclType(TD);
551+
MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
563552
} else if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(IIDecl)) {
564553
(void)DiagnoseUseOfDecl(IDecl, NameLoc);
565554
if (!HasTrailingDot)

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10963,14 +10963,20 @@ Sema::CheckTypenameType(ElaboratedTypeKeyword Keyword,
1096310963
//
1096410964
// FIXME: That's not strictly true: mem-initializer-id lookup does not
1096510965
// ignore functions, but that appears to be an oversight.
10966-
QualType T = getTypeDeclType(
10967-
Ctx,
10968-
Keyword == ETK_Typename ? DiagCtorKind::Typename : DiagCtorKind::None,
10969-
Type, IILoc);
10966+
auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(Ctx);
10967+
auto *FoundRD = dyn_cast<CXXRecordDecl>(Type);
10968+
if (Keyword == ETK_Typename && LookupRD && FoundRD &&
10969+
FoundRD->isInjectedClassName() &&
10970+
declaresSameEntity(LookupRD, cast<Decl>(FoundRD->getParent())))
10971+
Diag(IILoc, diag::ext_out_of_line_qualified_id_type_names_constructor)
10972+
<< &II << 1 << 0 /*'typename' keyword used*/;
10973+
1097010974
// We found a type. Build an ElaboratedType, since the
1097110975
// typename-specifier was just sugar.
10972-
return Context.getElaboratedType(
10973-
Keyword, QualifierLoc.getNestedNameSpecifier(), T);
10976+
MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false);
10977+
return Context.getElaboratedType(Keyword,
10978+
QualifierLoc.getNestedNameSpecifier(),
10979+
Context.getTypeDeclType(Type));
1097410980
}
1097510981

1097610982
// C++ [dcl.type.simple]p2:

clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,3 @@ template <typename T>
5858
FunS2 f;// No warning, entire function is deprecated, so usage here should be fine.
5959

6060
}
61-
62-
namespace GH58547 {
63-
struct A {
64-
using ta [[deprecated]] = int; // expected-note 2{{marked deprecated here}}
65-
};
66-
67-
using t1 = typename A::ta; // expected-warning {{'ta' is deprecated}}
68-
69-
template <class B1> struct B {
70-
using tb = typename B1::ta; // expected-warning {{'ta' is deprecated}}
71-
};
72-
73-
template struct B<A>; // expected-note {{requested here}}
74-
} // namespace GH58547

libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
// Deprecated in C++17
1515

16-
// FIXME: Remove 'clang-16' from UNSUPPORTED by 2022-11-05 (bugfix D136533).
17-
// UNSUPPORTED: c++03, c++11, c++14, clang-16
16+
// UNSUPPORTED: c++03, c++11, c++14
1817

1918
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
2019

@@ -24,11 +23,7 @@
2423
int main(int, char**)
2524
{
2625
std::allocator<int> a;
27-
TEST_IGNORE_NODISCARD a.allocate(3, nullptr);
28-
// expected-warning@-1 {{'allocate' is deprecated}}
29-
#if defined(TEST_CLANG_VER) && TEST_CLANG_VER >= 1600
30-
// expected-warning@*:* {{'pointer' is deprecated}}
31-
// expected-warning@*:* {{'const_pointer' is deprecated}}
32-
#endif
26+
TEST_IGNORE_NODISCARD a.allocate(3, nullptr); // expected-warning {{'allocate' is deprecated}}
27+
3328
return 0;
3429
}

0 commit comments

Comments
 (0)