2015-03-18 36 views
4

我的理论是gcc有一个bug。使用别名参考匿名结构会导致错误

using type = const struct {}&; 

但现在当我将其更改为右值引用它铿锵编译,但不能用gcc:在这两个铛和gcc以下编译

using type = const struct {}&&; 

// main.cpp:8:17: error: expected ';' after struct definition 
// typedef struct {}&& type; 
//    ^
// main.cpp:8:17: error: missing type-name in typedef-declaration 
// main.cpp:8:22: error: expected constructor, destructor, or type conversion before ';' token 
// typedef const struct {}&& type; 
//        ^

它无法与typedef版本,以及与同样的错误:

typedef const struct {}&& type; 

为什么这不能在gcc编译?这是标准问题还是错误?

回答

2

这看起来像一个gcc错误,对于无名类语法是覆盖在部分9[类],我们有以下几点:

class-specifier: 
    class-head { member-specificationopt} 
class-head: 
    class-key attribute-specifier-seqopt class-head-name class-virt-specifieropt base-clauseopt 
    class-key attribute-specifier-seqopt base-clauseopt 

和下面的文字:

A class-specifier whose class-head omits the class-head-name defines an unnamed class.

so an 未命名类只是一个类指定符没有名字和类说明符类型说明符和部分7.1.3[dcl.typedef]说:

The typedef specifier shall not be combined in a declspecifier- seq with any other kind of specifier except a type-specifier

并且不具有相对于任何限制无名类和在本段中仅指它们:

If the typedef declaration defines an unnamed class (or enum), the first typedef-name declared by the declaration to be that class type (or enum type) is used to denote the class type (or enum type) for linkage purposes only (3.5). [ Example:

typedef struct { } *ps, S; // S is the class name for linkage purposes 

—end example ]