Repository navigation
[clang][Sema] Warn on explicit conversion functions in C++20 with -Wc++98-compat - #217342
Merged
flash1729 merged 1 commit intoAug 20, 2026
Merged
Conversation
flash1729
marked this pull request as ready for review
August 19, 2026 14:35
|
@llvm/pr-subscribers-clang Author: Aditya Medhane (flash1729) ChangesThe explicit(bool) patch (76b9027) added a Drop the guard so every mode behaves the same, update the test, and remove the FIXME. Fixes #161689 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index b585161ba3ff4..0e5dab1e61de1 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -400,6 +400,9 @@ features cannot lower the translation-unit ABI level;
for pointer arithmetic on statically-sized arrays when the offset is a
non-negative constant within the array bounds.
+- `-Wc++98-compat` now diagnoses explicit conversion functions in C++20 and
+ later, matching the behavior in C++11 through C++17. (#GH161689)
+
### Improvements to Clang's time-trace
### Improvements to Coverage Mapping
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 8d5ee07c5ad49..e84d35b2b5ecb 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11613,7 +11613,7 @@ void Sema::CheckConversionDeclarator(Declarator &D, QualType &R,
R = Context.getFunctionType(ConvType, {}, Proto->getExtProtoInfo());
// C++0x explicit conversion operators.
- if (DS.hasExplicitSpecifier() && !getLangOpts().CPlusPlus20)
+ if (DS.hasExplicitSpecifier())
Diag(DS.getExplicitSpecLoc(),
getLangOpts().CPlusPlus11
? diag::warn_cxx98_compat_explicit_conversion_functions
diff --git a/clang/test/SemaCXX/cxx98-compat.cpp b/clang/test/SemaCXX/cxx98-compat.cpp
index 587c242271a02..265f16f514309 100644
--- a/clang/test/SemaCXX/cxx98-compat.cpp
+++ b/clang/test/SemaCXX/cxx98-compat.cpp
@@ -227,8 +227,7 @@ void TrivialButNonPODThroughEllipsis() {
}
struct HasExplicitConversion {
- // FIXME I think we should generate this diagnostic in C++20
- explicit operator bool(); // not-cpp20-warning {{explicit conversion functions are incompatible with C++98}}
+ explicit operator bool(); // expected-warning {{explicit conversion functions are incompatible with C++98}}
};
struct Struct {};
|
cor3ntin
approved these changes
Aug 19, 2026
Endilll
approved these changes
Aug 19, 2026
kieroxide
pushed a commit
to kieroxide/llvm-project
that referenced
this pull request
Aug 21, 2026
…++98-compat (llvm#217342) The explicit(bool) patch (76b9027) added a `!getLangOpts().CPlusPlus20` guard here, so this `-Wc++98-compat` warning stopped firing in C++20 and later. C++11 through C++17 still warn, and the test even has a FIXME asking for the warning in C++20. Drop the guard so every mode behaves the same, update the test, and remove the FIXME. Fixes llvm#161689
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The explicit(bool) patch (76b9027) added a
!getLangOpts().CPlusPlus20guard here, so this-Wc++98-compatwarning stopped firing in C++20 and later. C++11 through C++17 still warn, and the test even has a FIXME asking for the warning in C++20.Drop the guard so every mode behaves the same, update the test, and remove the FIXME.
Fixes #161689