Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheriting an explicit constructor (Intel C++)

Intel C++ compiler (Version 16.0.3.207 Build 20160415) seems to drop the explicit specifier when the constructor of the base class is inherited with using. Is this a bug?

struct B
{
    explicit B(int) { }
};

struct D : B
{
    using B::B;
};

B b = 1; // Not OK, fine
D d = 1; // Not OK with Microsoft C++ and GCC, but OK with Intel C++
like image 495
Evg Avatar asked Jan 05 '17 21:01

Evg


1 Answers

I believe that the appropriate wording from the standard is the following (n4296, 12.9 Inheriting constructors):

...

The constructor characteristics of a constructor or constructor template are

(2.1) — the template parameter list (14.1), if any,

(2.2) — the parameter-type-list (8.3.5), and

(2.3) — absence or presence of explicit (12.3.1).

For each non-template constructor in the candidate set of inherited constructors other than a constructor having no parameters or a copy/move constructor having a single parameter, a constructor is implicitly declared with the same constructor characteristics unless there is a user-declared constructor with the same signature in the complete class where the using-declaration appears or the constructor would be a default, copy, or move constructor for that class.

...

So most probably it is a bug in the Intel C++ compiler.

like image 78
Edgar Rokjān Avatar answered Nov 16 '22 16:11

Edgar Rokjān