- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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); }
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
BTW: I'm using icpc version 15.0.6 (gcc version 4.8.5 compatibility)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
K, thanks for the quick resolution!

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