Alias在msvc编译时通过,但被gcc拒绝。

huangapple go评论80阅读模式
英文:

Alias compiles with msvc but rejected by gcc

问题

Gcc表示“无法声明对已限定的引用类型的引用”,但msvc接受它。这是否是msvc的另一个错误,还是程序形式良好?

英文:

I have written the following code(that uses typedef), which compiles with microsoft visual studio but not with gcc and clang.

using type = int(int)&; 
using type2 = type&;   //compiles with msvc but rejcted in gcc and clang 

Gcc says cannot declare reference to qualified reference type but msvc accepts it.

Is this another bug of msvc or the program is well-formed?

答案1

得分: 2

The given program is ill-formed because if a function-type has reference qualifier then we cannot create a reference to that function-type as per dcl.ref:

[Note 4: Forming a reference to function type is ill-formed if the function type has cv-qualifiers or a ref-qualifier; see [dcl.fct].
— end note]

And since type1=int(int)& is a function type with a reference-qualifier, we cannot create a reference to type1 as you're trying to do in type2.

Thus, msvc is wrong here.

英文:

The given program is ill-formed because if a function-type has reference qualifier then we cannot create a reference to that function-type as per dcl.ref:

> [Note 4: Forming a reference to function type is ill-formed if the function type has cv-qualifiers or a ref-qualifier; see [dcl.fct].
— end note]


And since type1=int(int)& is a function type with a reference-qualifier, we cannot create a reference to type1 as you're trying to do in type2.

Thus, msvc is wrong here.

huangapple
  • 本文由 发表于 2023年5月14日 23:27:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76248268.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定