[Bug c++/85842] New: Bogus -Wreturn-type with generic lambda and constexpr if
ensadc at mailnesia dot com
gcc-bugzilla@gcc.gnu.org
Sat May 19 07:38:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85842
Bug ID: 85842
Summary: Bogus -Wreturn-type with generic lambda and constexpr
if
Product: gcc
Version: 8.1.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ensadc at mailnesia dot com
Target Milestone: ---
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`.
More information about the Gcc-bugs
mailing list