[PATCH] D133194: rewording note note_constexpr_invalid_cast
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 9 11:35:17 PDT 2022
aaron.ballman added inline comments.
================
Comment at: clang/lib/AST/ExprConstant.cpp:7476-7483
+ CCEDiag(E, diag::note_constexpr_invalid_cast)
+ << 0 << Info.Ctx.getLangOpts().CPlusPlus;
return static_cast<Derived*>(this)->VisitCastExpr(E);
}
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E) {
if (!Info.Ctx.getLangOpts().CPlusPlus20)
+ CCEDiag(E, diag::note_constexpr_invalid_cast)
----------------
You shouldn't pass the extra argument to either of these -- `0` maps to `reinterpret_cast` and `1` maps to `dynamic_cast` in the `%select{}`, neither of which use a `%1` placeholder.
================
Comment at: clang/lib/AST/ExprConstant.cpp:8896
CCEDiag(E, diag::note_constexpr_invalid_cast)
- << 3 << SubExpr->getType();
+ << 3 << SubExpr->getType() << Info.Ctx.getLangOpts().CPlusPlus;
else
----------------
This one should also drop the extra streamed argument for similar reasons as above.
================
Comment at: clang/test/Sema/cast.c:1-5
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown %s -verify -Wvla
+
+int array[(long)(char *)0]; // expected-warning {{variable length array used}} \
+ // expected-warning {{variable length array folded to constant array as an extension}} \
+ // expected-note {{this conversion is not allowed in a constant expression}}
----------------
I realized that we don't need to pass `-Wvla` at all, the other warning and note are on by default.
================
Comment at: clang/test/SemaCXX/constant-expression-cxx11.cpp:3
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_2b -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11 -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11 -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion -Wvla
+
----------------
We don't need to use `-Wvla` to see the diagnostic change, and this will fix the test failures from the other RUN lines not generating the same warning about use of a VLA.
================
Comment at: clang/test/SemaCXX/constant-expression-cxx11.cpp:15-17
+int array[(long)(char *)0]; // expected-warning {{variable length arrays are a C99 feature}} \
+ // expected-warning {{variable length array folded to constant array as an extension}} \
+ // expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
----------------
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133194/new/
https://reviews.llvm.org/D133194
More information about the cfe-commits
mailing list