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

#2304 Non-Explicit Ctor Warning for Move and Init list Ctors

olzhas_r_
New Contributor I
405 Views

These warnings seem to be false-positive.

Move and init-list constructors need to be implicit.

Other linting tools specificly omit these constructors.

The warning messages from icc:

home/.../src/linear_map.h(206): warning #2304: non-explicit constructor with single argument may cause implicit type conversion
    linear_map(std::initializer_list<value_type> init_list) {
    ^

/home/.../src/linear_map.h(216): warning #2304: non-explicit constructor with single argument may cause implicit type conversion
    linear_map(linear_map&& lm) noexcept : map_(std::move(lm.map_)) {}

 

0 Kudos
7 Replies
Judith_W_Intel
Employee
405 Views

 

It looks like you are using the -Weffc++ option. You will get lots of "false positive" warnings when using this option. Some people find it not very useful for that reason.

I'm not sure what you mean when you say that move and initializer_list constructors always need to be implicit -- doesn't it depend upon whether you or not you just want to use them in conversions or not?

0 Kudos
olzhas_r_
New Contributor I
405 Views
Judith Ward (Intel) wrote:

 

It looks like you are using the -Weffc++ option. You will get lots of "false positive" warnings when using this option. Some people find it not very useful for that reason.

I indeed use strict warnings from GCC: -Wall -Wextra -Wpedantic -Werror However, I ran ICC with '-Wno-effc++' to make sure that the error is not coming from that flag. When I ran with '-Weffc++' ICC produces a lot more warnings, so does GCC.
Judith Ward (Intel) wrote:

I'm not sure what you mean when you say that move and initializer_list constructors always need to be implicit -- doesn't it depend upon whether you or not you just want to use them in conversions or not?

Move ctors just like copy ctors are implicit by default. Explicit init_list ctors lead to some pretty ugly code: std::vector<:VECTOR>> v = {{1, 2}, {3, 4}}; // implicit std::vector<:VECTOR>> v = std::vector<:VECTOR>>{std::vector{1, 2}, std::vector{3, 4}}; // explicit I haven't seen these ctors explicit in libstdc++ or boost. cpplint flags non-explicit single arg ctors as well, but it excludes these special ctors: copy, move, init_list.
0 Kudos
Judith_W_Intel
Employee
405 Views

 

Are you sure you're not using -Weffc++?

I don't see the warning with the flags you mentioned, i.e.:

sptxl15-186> cat t.cpp

struct C {
   C(C&&);
};


sptxl15-187> icpc -std=c++11 -Wall -Wextra -Wpedantic -Werror -c t.cpp
icpc: command line warning #10006: ignoring unknown option '-Wpedantic'
sptxl15-188> icpc -std=c++11 -Weffc++ -c t.cpp
t.cpp(4): warning #2304: non-explicit constructor with single argument may cause implicit type conversion
     C(C&&);
     ^

sptxl15-189> icpc -std=c++11 -Weffc++ -Wno-effc++ -c t.cpp
sptxl15-190>

Can you cut and paste the command line you are using? Also what version of the compiler are you using?

thanks

Judy

thanks

Judy

 

 

0 Kudos
olzhas_r_
New Contributor I
405 Views
Judith Ward (Intel) wrote:

 

Can you cut and paste the command line you are using? Also what version of the compiler are you using?

icc (ICC) 16.0.3 20160415 I couldn't reproduce it with the snippet code. Hmm, that's strange. The project is built with CMake : https://github.com/rakhimov/scram
0 Kudos
olzhas_r_
New Contributor I
405 Views
I think I found the problem. GCC flag "-Wnon-virtual-dtor" makes ICC produce errors about non-explicit ctors. Tested with the code : struct A { A(A&& a) {} } I only enabled the "-Wnon-virtual-dtor" flag to get the bug reproduced.
0 Kudos
olzhas_r_
New Contributor I
405 Views

Please also note that even with "-Weffc++",

these warnings should not be produced.

This is false positives for fundamental reasons.

0 Kudos
olzhas_r_
New Contributor I
405 Views

I will file a separate bug report for "-Wnon-virtual-dtor" having a side effect with non-explict ctors.

0 Kudos
Reply