Skip to content

Commit bf343cc

Browse files
committed
[Clang] Duplicate diagnostics in C++20+ mode
1 parent 364aa4f commit bf343cc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

clang/include/clang/Sema/DeclSpec.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,23 @@ class CXXScopeSpec {
7676
NestedNameSpecifierLocBuilder Builder;
7777
ArrayRef<TemplateParameterList *> TemplateParamLists;
7878

79+
/// Flag indicating whether an incomplete-type diagnostic
80+
/// has already been emitted for this scope specifier.
81+
bool HadIncompleteTypeError = false;
82+
7983
public:
8084
SourceRange getRange() const { return Range; }
8185
void setRange(SourceRange R) { Range = R; }
8286
void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); }
8387
void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); }
8488
SourceLocation getBeginLoc() const { return Range.getBegin(); }
8589
SourceLocation getEndLoc() const { return Range.getEnd(); }
90+
91+
/// Return true if an incomplete-type diagnostic has already been emitted.
92+
bool hasIncompleteTypeError() const { return HadIncompleteTypeError; }
93+
94+
/// Mark that an incomplete-type error was emitted for this scope.
95+
void setIncompleteTypeError(bool v = true) { HadIncompleteTypeError = v; }
8696

8797
void setTemplateParamLists(ArrayRef<TemplateParameterList *> L) {
8898
TemplateParamLists = L;

clang/lib/Sema/SemaCXXScopeSpec.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,20 @@ bool Sema::RequireCompleteDeclContext(CXXScopeSpec &SS,
209209
SourceLocation loc = SS.getLastQualifierNameLoc();
210210
if (loc.isInvalid()) loc = SS.getRange().getBegin();
211211

212+
// If an incomplete-type error has already been emitted for this scope,
213+
// suppress duplicate diagnostics to avoid noisy repeated messages.
214+
if (SS.hasIncompleteTypeError())
215+
return true;
216+
212217
// The type must be complete.
213218
if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec,
214219
SS.getRange())) {
215220
SS.SetInvalid(SS.getRange());
221+
222+
// Remember that we've already diagnosed this incomplete type,
223+
// so later checks won't emit redundant diagnostics.
224+
SS.setIncompleteTypeError();
225+
216226
return true;
217227
}
218228

0 commit comments

Comments
 (0)