Skip to content

No longer diagnose __auto_type as the auto extension #134129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,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
----------------------------------

Expand Down
19 changes: 12 additions & 7 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
10 changes: 10 additions & 0 deletions clang/test/SemaCXX/cxx98-compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename ...T> // expected-warning {{variadic templates are incompatible with C++98}}
class Variadic1 {};

Expand Down