Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Unwarranted warnings: decltype vs. NULL references

vpozdyayev
Beginner
447 Views
Hello.
When building a project with /Wall (ICL 12.1.4.325), I get a number of warnings on the lines of

1>.h(303): warning #327: NULL reference is not allowed
1> -> std::enable_if< sizeof...( types ) != sizeof...( unpacked_types ), tuple< decltype( f( *( types * )nullptr ) )... > >::type

While normally I'd agree with this criticism, surely it has no point for an expression inside a decltype().

----
Best regards,
Vladimir
0 Kudos
5 Replies
Judith_W_Intel
Employee
447 Views

I'm having a hard time reproducing this...

sptxl8-302> cat ex.cpp

class types {};

template class C {};

template void f(T);

int main() {
C c;
return 0;
}
sptxl8-303> icpc -std=c++11 -Wall -c ex.cpp
sptxl8-304>

Can you please provide a reproducer?

thanks
Judy

0 Kudos
vpozdyayev
Beginner
447 Views
Actually, I have found more spurious warnings/remarks.
[cpp]#include class dereference { public: template< typename ptr_type > auto operator () ( ptr_type &ptr ) -> decltype( *ptr ) const { return *ptr; } }; template< typename fn_type, typename arg_type > auto app( fn_type fn, arg_type arg ) -> decltype(fn(*(arg_type*)nullptr)) { return fn( arg ); } template< typename... types > void test3( types... values ) { printf( "%d%d%dn", values... ); } int main() { int x = 123; app( dereference(), &x ); test3( 1, 2, 3 ); return 0; } [/cpp]
Command line: icl /Qstd=c++0x /Wall tests.cpp
Bad warnings:

tests.cpp(6): warning #2536: type qualifiers are meaningless here
auto operator () ( ptr_type &ptr ) -> decltype( *ptr ) const {

tests.cpp(12): warning #327: NULL reference is not allowed
auto app( fn_type fn, arg_type arg ) -> decltype(fn(*(arg_type*)nullptr)) {

tests.cpp(17): remark #869: parameter "values" was never referenced
void test3( types... values ) {

The last remark shows up in the actual project in a different context as "warning #869". I'm not sure if there is a signficant difference.

Regards,
Vladimir
0 Kudos
Judith_W_Intel
Employee
447 Views

thank you... I can now reproduce the warnings and remark.

For the first warning, "type qualifiers are meaningless here" -- I believe that warningis valid.
You are declaring the late specified return type as int const (after it is instantiated) and it is meaningless. If you were trying to declare the operator() member function itself as const then the const keyword should have gone before the ->.

Anyway I will submit bug reports for the 327 warning and the 869 remark since those do look incorrect.

thanks again,
Judy
0 Kudos
vpozdyayev
Beginner
447 Views
> For the first warning ...

Ah yes. Mea culpa. Although, shouldn't it also warn about "auto operator () ( ptr_type &ptr ) -> int const {" (with decltype() replaced by int) here? I guess I should have reported this one as a warning inconsistency.

Regards,
Vladimir
0 Kudos
JenniferJ
Moderator
447 Views
The "warning #327: NULL reference is not allowed" is now changed to "remark" in 13.0 update1. Jennifer
0 Kudos
Reply