diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 5e8df45e71d5..47f9c3caa0e4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -318,6 +318,9 @@ Improvements to Clang's diagnostics - 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. +- ``-Wc++98-compat`` no longer diagnoses use of ``__auto_type`` or + ``decltype(auto)`` as though it was the extension for ``auto``. (#GH47900) + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 2df961a48c7c..20240fdaf2bb 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -3376,13 +3376,18 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state, } else if (Auto && D.getContext() != DeclaratorContext::LambdaExpr) { // If there was a trailing return type, we already got // warn_cxx98_compat_trailing_return_type in the parser. - SemaRef.Diag(AutoRange.getBegin(), - D.getContext() == DeclaratorContext::LambdaExprParameter - ? diag::warn_cxx11_compat_generic_lambda - : IsDeducedReturnType - ? diag::warn_cxx11_compat_deduced_return_type - : diag::warn_cxx98_compat_auto_type_specifier) - << AutoRange; + // If there was a decltype(auto), we already got + // warn_cxx11_compat_decltype_auto_type_specifier. + unsigned DiagId = 0; + if (D.getContext() == DeclaratorContext::LambdaExprParameter) + DiagId = diag::warn_cxx11_compat_generic_lambda; + else if (IsDeducedReturnType) + DiagId = diag::warn_cxx11_compat_deduced_return_type; + else if (Auto->getKeyword() == AutoTypeKeyword::Auto) + DiagId = diag::warn_cxx98_compat_auto_type_specifier; + + if (DiagId) + SemaRef.Diag(AutoRange.getBegin(), DiagId) << AutoRange; } } diff --git a/clang/test/SemaCXX/cxx98-compat.cpp b/clang/test/SemaCXX/cxx98-compat.cpp index 43ba208d375c..8e7acf73923e 100644 --- a/clang/test/SemaCXX/cxx98-compat.cpp +++ b/clang/test/SemaCXX/cxx98-compat.cpp @@ -14,6 +14,16 @@ namespace std { }; } +void test_other_auto_spellings() { + __auto_type x = 0; // Ok + decltype(auto) y = 0; // expected-warning {{'decltype' type specifier is incompatible with C++98}} +#ifndef CXX14COMPAT + // expected-warning@-2 {{'decltype(auto)' type specifier is a C++14 extension}} +#else + // expected-warning@-4 {{'decltype(auto)' type specifier is incompatible with C++ standards before C++14}} +#endif +} + template // expected-warning {{variadic templates are incompatible with C++98}} class Variadic1 {};