Using a structure identifier to indicate POD types and C structures

Consider the following code snippet:

struct Foo {}; template<typename ForwardIterator> struct Foo* Bar(ForwardIterator first, ForwardIterator last) { (void)first; (void)last; Foo *foo(nullptr); return foo; } 

The above code snippet compiles in Clangv3.5 and GCCv4 0.9 .

However, it does not compile in VC ++ 2013.

Removing the struct identifier (see below) from the return type solves the problem:

 struct Foo {}; template<typename ForwardIterator> Foo* Bar(ForwardIterator first, ForwardIterator last) { (void)first; (void)last; Foo *foo(nullptr); return foo; } 

Q1:

Is this a visual studio bug?

Q2:

This problem arose because there is a .hc file in my Foo struct .hc (i.e. is a C struct ) and to use C / POD struct in my code, I use the identifier struct . Is this a bad idea (i.e., in C ++ code, should I avoid using the struct identifier this way)?

+8
c ++ struct c ++ 11 visual-studio-2013 c ++ 14
source share
1 answer

The bulk of the specified type specifiers is to allow you to refer to a name that was hidden from the C ++ draft standard in section 3.4.4 Specific type specifiers:

A specifier of a specified type (7.1.6.3) can be used to indicate a previously declared class name or an enumeration name, even if the name has been hidden by a non-type declaration (3.3.10).

and therefore, in the case where Foo hidden, you will have to use specifiers of the specified type:

 struct Foo {}; void Foo() { } 

I see nothing in 7.1.6.3 specified type or 14 Patterns that would prevent this use. Actually this is similar to the description of CS2989 Visual Studio gets confused and thinks that you are trying to redefine a class without a template as a template class.

So it looks like an error to me, so I would write a bug report .

Refresh

An error message has been submitted.

+7
source share

All Articles