Bug 57857 - argument of decltype used by no return value warning
Summary: argument of decltype used by no return value warning
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-07-09 02:42 UTC by David Krauss
Modified: 2021-08-04 19:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 6.1.0
Known to fail: 5.5.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Krauss 2013-07-09 02:42:12 UTC
The following program complains that "declval() must not be used!" in a static assertion if -Wall is passed. But declval() is only present in the unevaluated context of a decltype specifier.

The issue seems to be linked to the generation of the warning message. But the warning message will be present without the static_assert if the function has more than one exit point, such as if(0) throw; or if(0) return; (the latter using -fpermissive).


#include <utility>

template <typename U>
auto foo() -> decltype(std::declval<U>() + std::declval<U>());

template <typename T>
decltype(foo<T>()) bar(T) {
//  if ( 0 ) throw;
}

int main()
{ bar(1); }
Comment 1 David Krauss 2013-07-09 02:45:59 UTC
Narrowing down the cause, the statement { 0; } silences the error but { void(0); } does not.
Comment 2 Andrew Pinski 2021-08-04 19:27:01 UTC
GCC 6+ produces:
<source>: In instantiation of 'decltype (foo<T>()) bar(T) [with T = int; decltype (foo<T>()) = int]':
<source>:13:8:   required from here
<source>:10:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

And no calling of the static_assert .