struct A{ constexpr operator bool()const{ return true; } }; int main(){ auto f = [](auto v){ if constexpr(v){} }; A a; f(a); } $ g++ -std=c++17 main.cpp main.cpp: In lambda function: main.cpp:6:40: error: 'v' is not a constant expression auto f = [](auto v){ if constexpr(v){} }; ^ $ g++ --version g++ (GCC) 8.0.1 20180216 (experimental) Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Known to work with GCC-7: $ g++-7 --version g++ (GCC) 7.3.1 20180216 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Started with r255390.
Is that really a rejects-valid, rather than previous accepts-invalid that PR83273 fixed? The lambda parameter is not a constant expression, the conversion operator is.
(In reply to Jakub Jelinek from comment #2) > Is that really a rejects-valid Yes, bool(v) is a constant-expression.
Author: jason Date: Fri Feb 16 16:44:17 2018 New Revision: 257744 URL: https://gcc.gnu.org/viewcvs?rev=257744&root=gcc&view=rev Log: PR c++/84421 - type-dependent if constexpr * semantics.c (finish_if_stmt_cond): Check type_dependent_expression_p. Added: trunk/gcc/testsuite/g++.dg/cpp1z/constexpr-if14.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/semantics.c
Fixed.