英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论