in icpc (ICC) 19.0.0.117 20180804, if I have a function with auto return type and a non-ambiguous "if constexpr" stanza like this:
template<typename ... ARGS> auto foo(ARGS ... args) { if constexpr (sizeof...(args) == 1) { return /* variable of some type */; } else { return /* variable of another type */ } }
I get error #1011: missing return statement at end of non-void function. GCC is fine with it. I can't figure a work-around except to fall back to SFINAE and enable_if
Link Copied
you can add -wd1011 to your command line.
Thanks,
Viet
That's great, and works. But is there a way to apply that in a limited scope? I tried
#pragma warning (disable:1011)
...but that didn't work.
$ icpc t.cpp -c -w3
t.cpp(1): remark #1418: external function definition with no prior declaration
int foo ( int i) {
^
t.cpp(4): warning #1011: missing return statement at end of non-void function "foo"
}
^
t.cpp(2): remark #593: variable "b" was set but never used
int b ;
^
$ icpc t2.cpp -c -w3
t2.cpp(3): remark #1418: external function definition with no prior declaration
int foo ( int i) {
^
t2.cpp(4): remark #593: variable "b" was set but never used
int b ;
^
$ diff t.cpp t2.cpp
0a1,2
> #pragma warning (disable:1011)
>
$
Thank you for responding. This does work, but what I discovered is that if you try to use it around template code with #pragma warning (push) and (pop), then it doesn't disable the warning for the ultimate instantiations of the template. It does work if I locate every instantiation of the template and bracket all that code with push/disable/pop.
Try:
if constexpr (sizeof...(args) >= 1) { if constexpr (sizeof...(args) == 1) { return /* variable of some type */; } else { return /* variable of another type */ } } return /* variable of acceptable type */
Thanks, Jim, but that doesn't work if you actually instantiate the template.
This is a known limitation of using this pragma. Template instantiations aren't done until after parsing the entire source file so only the pragmas that were in effect at the end of the file will be applied.
For more complete information about compiler optimizations, see our Optimization Notice.