Community
cancel
Showing results for 
Search instead for 
Did you mean: 
andreas_s_4
Beginner
70 Views

Disabling warning #2304 for class templates

I'm writing a library in which a class template relies on implicit type conversions. Hence I'd like to turn that warning off. This works well if the class is not a template, but doesn't work for templates (see code below). Am I holding this wrong?

Thanks in advance!

-Andreas

 

#include <iostream>

#ifdef __ICC
#pragma warning push
#pragma warning (disable: 2304)
#endif

template<typename CARGO>
class short_vec1
{
public:
    // icpc issues warning #2304 fo this line even though the warning
    // is switched off...
    short_vec1(CARGO)
    {}
};

class short_vec2
{
public:
    // ...and not for this line (which is correct).
    short_vec2(double)
    {}
};

#ifdef __ICC
#pragma warning pop
#endif

int main()
{
    short_vec1<double> s(4.3);
    short_vec2 t(4.3);
}

 

0 Kudos
7 Replies
andreas_s_4
Beginner
70 Views

BTW: I'm using icpc version 15.0.6 (gcc version 4.8.5 compatibility)
 

Judith_W_Intel
Employee
70 Views

 

The warning is occurring at the point of the template instantiation (not at the point of the template declaration).

So you'd need to move the #pragma warning pop after the declaration of s in order to disable it.

Judy

Yuan_C_Intel
Employee
70 Views

Hi, Andreas

I cannot reproduce the warning with icc 15.0.6, gcc 4.8.2.

What's the compiler option  you used? 

Simply tried:

$ icc test.cpp -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.6.233 Build 20151119
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

Edison Design Group C/C++ Front End, version 4.8 (Nov 20 2015 02:24:47)
Copyright 1988-2013 Edison Design Group, Inc.

 

Thanks.

andreas_s_4
Beginner
70 Views

Hey Yolanda,

here's a gist of how I'm compiling. Strangely the warning is only issued if I add -Wnon-virtual-dtor. It doesn't occurr with -Wall only:

Thanks!

gentryx@neuromancer ~ $ icpc -V -Wall -Wnon-virtual-dtor test.cpp -o test
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0 Build 20151119
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.
FOR NON-COMMERCIAL USE ONLY

Edison Design Group C/C++ Front End, version 4.8 (Nov 20 2015 02:24:47)
Copyright 1988-2013 Edison Design Group, Inc.

test.cpp(14): warning #2304: non-explicit constructor with single argument may cause implicit type conversion
      short_vec1(CARGO)
      ^
          detected during instantiation of class "short_vec1<CARGO> [with CARGO=double]" at line 32

GNU ld (Gentoo 2.26.1 p1.0) 2.26.1



 

 

andreas_s_4
Beginner
70 Views

Judith-

My problem is that I'm a library writer. So unless all users disable this warning, they will all be spammed with warnings on code that's entirely safe. Is there a way to disable warnings from the site of the definition, not the instantiation site?

Thanks!

-Andreas

 

Judith_W_Intel
Employee
70 Views

 

No there is not.

As already discussed in this thread

https://software.intel.com/en-us/forums/intel-c-compiler/topic/673428#comment-1881102

We shouldn't be issuing the diagnostic at all -- and this problem has been fixed recently.

Judy

andreas_s_4
Beginner
70 Views

K, thanks for the quick resolution!