Skip to content

Commit 7febd78

Browse files
authored
No longer diagnose __auto_type as the auto extension (llvm#134129)
Given: __auto_type x = 12; decltype(auto) y = 12; -Wc++98-compat would diagnose both x and y with: 'auto' type specifier is incompatible with C++98 This patch silences the diagnostic in those cases. decltype(auto) is still diagnosed with: 'decltype(auto)' type specifier is incompatible with C++ standards before C++14 as expected but no longer produces the extraneous diagnostic about use of 'auto'. Fixes llvm#47900
1 parent ee4e819 commit 7febd78

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ Improvements to Clang's diagnostics
318318

319319
- Split diagnosing base class qualifiers from the ``-Wignored-Qualifiers`` diagnostic group into a new ``-Wignored-base-class-qualifiers`` diagnostic group (which is grouped under ``-Wignored-qualifiers``). Fixes #GH131935.
320320

321+
- ``-Wc++98-compat`` no longer diagnoses use of ``__auto_type`` or
322+
``decltype(auto)`` as though it was the extension for ``auto``. (#GH47900)
323+
321324
Improvements to Clang's time-trace
322325
----------------------------------
323326

clang/lib/Sema/SemaType.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,13 +3376,18 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
33763376
} else if (Auto && D.getContext() != DeclaratorContext::LambdaExpr) {
33773377
// If there was a trailing return type, we already got
33783378
// warn_cxx98_compat_trailing_return_type in the parser.
3379-
SemaRef.Diag(AutoRange.getBegin(),
3380-
D.getContext() == DeclaratorContext::LambdaExprParameter
3381-
? diag::warn_cxx11_compat_generic_lambda
3382-
: IsDeducedReturnType
3383-
? diag::warn_cxx11_compat_deduced_return_type
3384-
: diag::warn_cxx98_compat_auto_type_specifier)
3385-
<< AutoRange;
3379+
// If there was a decltype(auto), we already got
3380+
// warn_cxx11_compat_decltype_auto_type_specifier.
3381+
unsigned DiagId = 0;
3382+
if (D.getContext() == DeclaratorContext::LambdaExprParameter)
3383+
DiagId = diag::warn_cxx11_compat_generic_lambda;
3384+
else if (IsDeducedReturnType)
3385+
DiagId = diag::warn_cxx11_compat_deduced_return_type;
3386+
else if (Auto->getKeyword() == AutoTypeKeyword::Auto)
3387+
DiagId = diag::warn_cxx98_compat_auto_type_specifier;
3388+
3389+
if (DiagId)
3390+
SemaRef.Diag(AutoRange.getBegin(), DiagId) << AutoRange;
33863391
}
33873392
}
33883393

clang/test/SemaCXX/cxx98-compat.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ namespace std {
1414
};
1515
}
1616

17+
void test_other_auto_spellings() {
18+
__auto_type x = 0; // Ok
19+
decltype(auto) y = 0; // expected-warning {{'decltype' type specifier is incompatible with C++98}}
20+
#ifndef CXX14COMPAT
21+
// expected-warning@-2 {{'decltype(auto)' type specifier is a C++14 extension}}
22+
#else
23+
// expected-warning@-4 {{'decltype(auto)' type specifier is incompatible with C++ standards before C++14}}
24+
#endif
25+
}
26+
1727
template<typename ...T> // expected-warning {{variadic templates are incompatible with C++98}}
1828
class Variadic1 {};
1929

0 commit comments

Comments
 (0)