- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Tags:
- CC++
- Development Tools
- Intel® C++ Compiler
- Intel® Parallel Studio XE
- Intel® System Studio
- Optimization
- Parallel Computing
- Vectorization
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
you can add -wd1011 to your command line.
Thanks,
Viet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
$ 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)
>
$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Jim, but that doesn't work if you actually instantiate the template.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page