Bug 84421 - [8 Regression] Lambda parameter is no longer a core constant expressions
Summary: [8 Regression] Lambda parameter is no longer a core constant expressions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0.1
: P3 normal
Target Milestone: 8.0
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2018-02-16 13:54 UTC by Benjamin Buch
Modified: 2018-02-16 16:45 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-02-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Buch 2018-02-16 13:54:23 UTC
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.
Comment 1 Marek Polacek 2018-02-16 14:01:39 UTC
Started with r255390.
Comment 2 Jakub Jelinek 2018-02-16 15:27:57 UTC
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.
Comment 3 Jason Merrill 2018-02-16 15:38:18 UTC
(In reply to Jakub Jelinek from comment #2)
> Is that really a rejects-valid

Yes, bool(v) is a constant-expression.
Comment 4 Jason Merrill 2018-02-16 16:44:56 UTC
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
Comment 5 Jason Merrill 2018-02-16 16:45:01 UTC
Fixed.