diff options
-rw-r--r-- | gcc/cp/constexpr.c | 9 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/bit-cast8.C | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/bit-cast9.C | 15 |
4 files changed, 39 insertions, 0 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index a299d9a..0c12f60 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -6900,6 +6900,15 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, return t; case BIT_CAST_EXPR: + if (lval) + { + if (!ctx->quiet) + error_at (EXPR_LOCATION (t), + "address of a call to %qs is not a constant expression", + "__builtin_bit_cast"); + *non_constant_p = true; + return t; + } r = cxx_eval_bit_cast (ctx, t, non_constant_p, overflow_p); break; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 9d2ca30..b448efe 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -10761,6 +10761,10 @@ cp_build_bit_cast (location_t loc, tree type, tree arg, tree ret = build_min (BIT_CAST_EXPR, type, arg); SET_EXPR_LOCATION (ret, loc); + + if (!processing_template_decl && CLASS_TYPE_P (type)) + ret = get_target_expr_sfinae (ret, complain); + return ret; } diff --git a/gcc/testsuite/g++.dg/cpp2a/bit-cast8.C b/gcc/testsuite/g++.dg/cpp2a/bit-cast8.C new file mode 100644 index 0000000..17a4165 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/bit-cast8.C @@ -0,0 +1,11 @@ +// PR c++/98469 +// { dg-do compile { target c++20 } } +// { dg-options "-Wall" } + +struct S { int s; }; + +S +foo () +{ + return __builtin_bit_cast (S, 0); +} diff --git a/gcc/testsuite/g++.dg/cpp2a/bit-cast9.C b/gcc/testsuite/g++.dg/cpp2a/bit-cast9.C new file mode 100644 index 0000000..bf3d368 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/bit-cast9.C @@ -0,0 +1,15 @@ +// PR c++/98469 +// { dg-do compile { target c++20 } } +// { dg-options "-Wall" } + +template<typename T, typename F> +constexpr T +bit_cast (const F &f) noexcept +{ + return __builtin_bit_cast (T, f); +} +struct S { int s; }; +constexpr int foo (const S &x) { return x.s; } +constexpr int bar () { return foo (bit_cast<S> (0)); } +constexpr int x = bar (); +static_assert (!x); |