2015-03-18 82 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 ]