Bug 85842 - [8/9 Regression] Bogus -Wreturn-type with generic lambda and constexpr if
Summary: [8/9 Regression] Bogus -Wreturn-type with generic lambda and constexpr if
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.1.0
: P2 normal
Target Milestone: 8.2
Assignee: Jason Merrill
URL:
Keywords: diagnostic
: 86495 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-05-19 07:38 UTC by ensadc
Modified: 2018-07-13 09:37 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.3.0
Known to fail: 8.1.0, 9.0
Last reconfirmed: 2018-05-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ensadc 2018-05-19 07:38:02 UTC
https://wandbox.org/permlink/qSgjLEWzpsJmkHNU

----
template<class T>
auto f = [](auto&& arg) -> T* {
    if constexpr (sizeof(arg) == 1) {
        return nullptr;
    } else {
        return static_cast<T*>(&arg);
    }
};

auto p = f<int>(0);

----
prog.cc: In instantiation of 'auto f<int>':
prog.cc:10:10:   required from here
prog.cc:2:6: warning: no return statement in function returning non-void [-Wreturn-type]
 auto f = [](auto&& arg) -> T* {
      ^

----
This warning is bogus because both branches of `if constexpr` have a return statement.

The warning will disappear when `if constexpr` is changed to `if`.
Comment 1 Jonathan Wakely 2018-05-20 19:15:31 UTC
Started with r259043

            PR c++/85149 - generic lambda and constexpr if.
    
            * pt.c (build_extra_args, add_extra_args): Split from
            tsubst_pack_expansion.
            (tsubst_expr) [IF_STMT]: Use them.
            * cp-tree.h (IF_STMT_EXTRA_ARGS): New.
Comment 2 Jason Merrill 2018-05-24 20:03:50 UTC
Author: jason
Date: Thu May 24 20:03:18 2018
New Revision: 260685

URL: https://gcc.gnu.org/viewcvs?rev=260685&root=gcc&view=rev
Log:
	PR c++/85842 - -Wreturn-type, constexpr if and generic lambda.

	* pt.c (tsubst_lambda_expr): Copy current_function_returns_* to
	generic lambda.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1z/constexpr-if23.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
Comment 3 Jason Merrill 2018-05-24 20:04:28 UTC
Author: jason
Date: Thu May 24 20:03:56 2018
New Revision: 260686

URL: https://gcc.gnu.org/viewcvs?rev=260686&root=gcc&view=rev
Log:
	PR c++/85842 - -Wreturn-type, constexpr if and generic lambda.

	* pt.c (tsubst_lambda_expr): Copy current_function_returns_* to
	generic lambda.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/cpp1z/constexpr-if23.C
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/pt.c
Comment 4 Jason Merrill 2018-05-25 14:36:10 UTC
Fixed.
Comment 5 Jakub Jelinek 2018-07-13 09:37:57 UTC
*** Bug 86495 has been marked as a duplicate of this bug. ***