Можно ли использовать имена typedef для объявления или определения конструкторов?

Стандартный :

[class.ctor] 12.1/1 говорит

A special declarator syntax is used to declare or define the constructor. The syntax uses:

    — an optional decl-specifier-seq in which each decl-specifier is either a function-specifier or constexpr,

    — the constructor’s class name, and

    — a parameter list

in that order.

[class.name] 9.1/4 говорит

A typedef-name (7.1.3) that names a class type, or a cv-qualified version thereof, is also a class-name. If a typedef-name that names a cv-qualified class type is used where a class-name is required, the cv-qualifiers are ignored. A typedef-name shall not be used as the identifier in a class-head.

Также [expr.prim.general] 5.1.1/8 говорит

Where class-name :: class-name is used, and the two class-names refer to the same class, this notation names the constructor (12.1).


Приложение:

Мне кажется, это говорит о том, что объявление конструктора должно быть разрешено с использованием имен typedef (, несмотря на то, что 12.1/1 не использует выделенное курсивом имя класса -).

Например, учитывая:

struct Foo;
typedef Foo Bar;

тогда

struct Foo { Bar() {} }; // defines Foo's constructor. - 1

или вместо этого дано

struct Foo;
struct Foo { Foo() };
typedef Foo Bar;

затем

Foo::Bar() {}; // defines Foo's constructor - 2

или

Bar::Bar() {}; // defines Foo's constructor - 3

или

Bar::Foo() {}; // defines Foo's constructor - 4

Любое из них должно быть законным. Однако кажется, что никто не принимает определения 2 или 3, MSVC принимает 1, а MSVC, clang и gcc принимают 4.

Верен ли мой анализ и ошибаются ли все эти компиляторы?

14
задан bames53 13 July 2012 в 22:03
поделиться