Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Alias compiles with msvc but rejected by gcc

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading