Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

typename required or not.

AndrewC
New Contributor III
783 Views
In the following code, the typename keyword is required by Intel compiler 12.1.0 on Linux ( all loptions default), but not by Intel compiler 12.1.1.258 ( all options default) on windows. Not sure who is correct.
[cpp]template
class edge_struct 
{  
public:
	typedef  edge_struct* edge;
	V v_;
	E e_;
	F f_;
};
 
template
void Succ_Inout_Edge2(edge_struct* e) 
{ 
	typename edge_struct::edge x;

}

 
template
typename edge_struct::edge Succ_Inout_Edge(typename edge_struct::edge e) 
{ 
	typename edge_struct::edge e2 = e;
  	return e2;
}


void a(void)
{
	edge_struct a;
	edge_struct::edge e=0;
	Succ_Inout_Edge2(e);
}

[/cpp]
0 Kudos
1 Solution
Georg_Z_Intel
Employee
783 Views
Hello,

after checking with our front-end developers we created a ticket to consider removing the implicit typename feature for future compiler versions ([edit: using existing ticket] DPD200178660 DPD200135843).
You're right that this relict is hindering cross-development and confusing nowadays.

As soon as this is implemented I'll let you know.

Best regards,

Georg Zitzlsberger

View solution in original post

0 Kudos
12 Replies
AndrewC
New Contributor III
783 Views
After investigation the typename keyword strictly is required, I can only assume that the windows compiler is doing its Visual C++ compatibility thing by letting it through without typename
0 Kudos
SergeyKostrov
Valued Contributor II
783 Views

...
template< class V, class E, class F >
typename edge_struct< V, E, F >::edge Succ_Inout_Edge( typename edge_struct< V, E, F >::edge e )
{
typename edge_struct< V, E, F >::edge e2 = e;
return e2;
};
...

It was told many times that on Windows platforms Intel C/C++ compileris compatible with MSVC C/C++
compiler. So, this is whatMSVC outputs ifany of underlined 'typename' template specifiers removed:

...
... : warning C4346: 'edge_struct::edge' : dependent name is not a type prefix with 'typename' to indicate a type
... : error C2146: syntax error : missing ';' before identifier 'Succ_Inout_Edge'
... : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
... : fatal error C1903: unable to recover from previous error(s); stopping compilation
...

It looks like a featureofIntel C/C++ compiler for Windows, or a bug?

Best regards,
Sergey

PS: 'g++'compiler for Windowsalso fails...

0 Kudos
SergeyKostrov
Valued Contributor II
783 Views
Quoting vasci_intel
After investigation the typename keyword strictly is required, I can only assume that the windows compiler is doing its Visual C++ compatibility thing by letting it through without typename


Please take a look atoutput ofVisual C++in aPost #2.

0 Kudos
AndrewC
New Contributor III
783 Views
Good point, the Visual Studio 2010 compiler ( and gcc 4.1.2) does fail to compile as well unless typename is present.

I would expect the same version of the Intel compiler on Linux and Windows would , with the "appropriate" options , behave the same way.
0 Kudos
Georg_Z_Intel
Employee
783 Views
Hello,

that's indeed because of different behavior between Linux* & Windows* versions in terms of compatibility.
Following the C++ standard it requires typename. For Linux* we conform to that, hence you're seeing an error there.
But why don't we error with the Windows* version, too? Well, VS compilers before 2003 had a feature to "detect" missing typename keywords (implicit typename feature). Back in 2009 we already discussed that internally but the only "problem" was that our compiler would also tolerate less strict C++ code. As we're missing a hard case proving this wrong we still support the implicit typename feature... for Windows* platforms.

If you find an example where the implicit typename feature causes problems, please let me know.

Best regards,

Georg Zitzlsberger
0 Kudos
AndrewC
New Contributor III
783 Views
OK , makes sense. But the point is Intel 12.1.1 on Windows now behaves differently to Visual C++ 2010. Visual C++ 2010 will not compile the code without typename present , while Intel 12.1.1 happily accepts it.
0 Kudos
Georg_Z_Intel
Employee
783 Views
Hello,

yes, but as Sergey mentioned it's a feature here. The opposite would be a real problem for our compiler.
I admit that having an option to disable this (or vice versa) would aid in creating standards-compliant code, though.
Besides this observation, is it a real problem for your development or rather theoretic?

Best regards,

Georg Zitzlsberger
0 Kudos
AndrewC
New Contributor III
783 Views
Its a real problem as I do primary development on Windows and then "port" to Linux. This was a nasty suprise as this required editing maybe a 100 files to get the "typename" usage correct.

The easiest way fior me was to temporarily switch to the MS Visual Studio 2010 compiler on Windows which at least caught the worst errors, then do the final set of fixes on linux.

e.g. MS Visual Studio accepts typename const XXXX whereas the correct form, I gather, is const typename XXXX

I suppose we have a situation where MS Compiler (Windows) <> Intel Compiler (windows) <> Intel compiler (Linux). Not sure that is ideal, really.
0 Kudos
SergeyKostrov
Valued Contributor II
783 Views
...
yes, but as Sergey mentioned it's a feature here.

[SergeyK] Actually, my statement was:

It looks like a featureofIntel C/C++ compiler for Windows, or a bug?

The opposite would be a real problem for our compiler.

[SergeyK] Now I think, it is more a "bug" than a "feature".


Best regards,
Sergey

0 Kudos
SergeyKostrov
Valued Contributor II
783 Views
Did you try a workaround like:

...
#if defined (_LINUX32 )
#if _ICC_VER == // ICC
#define DeclTypename typename
#define ImplTypename typename
#endif
#endif
#if defined ( _WIN32 )
#if _MSC_VER == 1600 // VS2010
#define DeclTypename
#define ImplTypename
#endif
#endif
...

...
template< class V, class E, class F >
DeclTypename edge_struct< V, E, F >::edge Succ_Inout_Edge( DeclTypename edge_struct< V, E, F >::edge e )
{
ImplTypename edge_struct::edge e2 = e;
return e2;
}
...

Of course, it could be more complex in your case...
0 Kudos
AndrewC
New Contributor III
783 Views
If I use typename as required by the C++ standard then the code is ok with all compilers, so no need for conditional defines. It was just a PITA to go through my code and fix all the problems.... done now...
0 Kudos
Georg_Z_Intel
Employee
784 Views
Hello,

after checking with our front-end developers we created a ticket to consider removing the implicit typename feature for future compiler versions ([edit: using existing ticket] DPD200178660 DPD200135843).
You're right that this relict is hindering cross-development and confusing nowadays.

As soon as this is implemented I'll let you know.

Best regards,

Georg Zitzlsberger
0 Kudos
Reply