GCC 3.4很挑剔 [英] GCC 3.4 being picky

查看:106
本文介绍了GCC 3.4很挑剔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在测试gcc-3.4分支(用'make profilebootstrap'加速构建

由大量编译10%!)


它更符合C ++标准(因此这不是OT

帖子。)我很难搞清楚它想要我做什么。这里是

一些代码,以及生成的错误消息。


命名空间NA

{

名称空间N1

{


模板< typename SomeT>

class Tmp1

{< br $>
};


模板< typename T1,typename T2 = Tmp1< T1> >

class C1

{

public:

template< unsigned i>

class C2

{

};

};


};


};


命名空间NA

{


命名空间N2

{


模板< typename B>

B

a_func(const N1 :: C1< B> ; ::模板C2< 3>& arg)

{

}


};


};


int

main()

{

使用命名空间NA;

使用命名空间N1;

N1 :: C1< double> :: C2< 3> v;


N2 :: a_func< double>(v);


返回0;

}


one.cc:40:错误:在''&''令牌之前预期不合格的身份

one.cc:40:错误:预期`, ''或`'''在''&''之前''令牌

one.cc:41:错误:ISO C ++禁止声明`参数''没有类型

one.cc:在函数`int main()'':

one.cc:55:错误:无法转换`NA :: N1 :: C1< double,

NA :: N1 :: Tmp1< double> > :: C2< 3u>''到'int''参数'1''到'B

NA :: N2 :: a_func(int)[有B =双]''


我知道'a_func ....'行的问题。


之前看过:

a_func(const N1 :: C1< B> :: C2< 3& arg)


并给出了错误消息:

one.cc:40:错误:非模板`C2''用作模板

one.cc:40:错误:(使用`NA :: N1 :: C1< B,NA :: N1 :: Tmp1< T1>> ::模板C2''

表示它是模板)

one.cc:40:错误:预期不合格 - id'')''令牌

想法?我终于使用

vector-maths库来获取我的SSE优化模板表达式,因为GCC并没有充满

模板解析错误,但似乎我无法弄清楚正确的

行为:-)


谢谢,

Asfand Yar


-
http ://www.it-is-truth.org/

推荐答案

Asfand Yar Qazi写道:
Asfand Yar Qazi wrote:
名称空间NA
名称空间N2
{

模板< typename B>
B
a_func (const N1 :: C1< B> ::模板C2& arg)
{$ / $}


[...]

我知道'a_func ....'行的问题。

在读之前:
a_func(const N1 :: C1< B>: :C2< 3& arg)
namespace NA
{

namespace N2
{

template<typename B>
B
a_func(const N1::C1<B>::template C2<3>& arg)
{
}
[...]
I know its some problem with the ''a_func ....'' line.

Before it read:
a_func(const N1::C1<B>::C2<3>& arg)




我不知道这是多少多余的,但这是合法的:


a_func(const typename N1 :: template C1< B> :: template C2< 3> &安培; arg)


-

问候,

巴斯特。



I don''t know how much of this is redundant, but it''s legal:

a_func (const typename N1::template C1 <B>::template C2 <3> & arg)

--
Regards,
Buster.


Asfand Yar Qazi写道:
Asfand Yar Qazi wrote:
命名空间NA
{
命名空间N2
{

模板< typename B>
B
a_func(const N1 :: C1< B> ::模板C2< 3& arg)
{
}


[...]

我知道'a_func ....'行的问题。

在阅读之前:
a_func(const N1 :: C1< B> :: C2< 3& arg)
namespace NA
{

namespace N2
{

template<typename B>
B
a_func(const N1::C1<B>::template C2<3>& arg)
{
}
[...]
I know its some problem with the ''a_func ....'' line.

Before it read:
a_func(const N1::C1<B>::C2<3>& arg)




我不知道这多少是多余的,但这是合法的:


a_func(const typename N1 :: template C1< B> :: template C2< 3& arg)


-

问候,

巴斯特。



I don''t know how much of this is redundant, but it''s legal:

a_func (const typename N1::template C1 <B>::template C2 <3> & arg)

--
Regards,
Buster.


模板< typename B>

B

a_func(const typename N1 :: template C1< B> :: template C2< 3& arg)

{

}


或许可以解释一下。在参数列表中,


" N1"很好。它不依赖于模板参数,并且已经定义了
。它绝对是名称空间的名称。


" N1 :: C1"也可以:它绝对是模板的名称。


" N1 :: C1< B>"因此也是可以的。


N1 :: C1< B> :: C2"可能不是模板的名称(*)!它取决于B上的



编译器应该假设它不是模板。因此

此名称后的''<''被解释为小于运算符。

语法错误。我们必须说N1 :: C1< B> ::模板C2。相反。


N1 :: C1< B> ::模板C2< 3>可能不是类型的名称(**)!它
取决于B和3.编译器应该假设它是_not_

类型的名称。因此,跟随此名称的''&''被解释为
作为按位和运算符。语法错误。我们必须说

" typename N1 :: C1< B> :: template C2< 3>"相反。


因此,最终的参数声明变为

const typename N1 :: C1< B> :: template C2< 3> &安培; arg。


额外的模板我在上一篇文章中输入并没有造成任何伤害

但这是多余的。


(*)//我们可以_make_ C2不是模板,使用部分专业化:

名称空间N1 {template<> C1类< int> {int C2; }; }

// ...

void f(){N1 :: C1< int> :: C2< 3> &安培; ARG; } //哎哟。


(**)//同样。


-

问候,

巴斯特。
template <typename B>
B
a_func (const typename N1::template C1 <B>::template C2 <3> & arg)
{
}

Perhaps an explanation is in order. In the parameter list,

"N1" is fine. It is not dependent on a template argument and has already
been defined. It is definitely the name of a namespace.

"N1::C1" is also OK: it is definitely the name of a template.

"N1::C1 <B>" is therefore OK too.

"N1::C1 <B>::C2" might not be the name of a template (*)! It depends
on B.

The compiler is supposed to assume it is _not_ a template. Therefore
the ''<'' following this name is interpreted as the less-than operator.
Syntax error. We have to say "N1::C1 <B>::template C2" instead.

"N1::C1 <B>::template C2 <3>" might not be the name of a type (**)! It
depends on B and 3. The compiler is supposed to assume it is _not_ the
name of a type. Therefore the ''&'' following this name is interpreted
as the bitwise-and operator. Syntax error. We have to say
"typename N1::C1 <B>::template C2 <3>" instead.

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".

The extra "template" I put in in my previous post doesn''t do any harm
but it is redundant.

(*) // We can _make_ C2 not be a template, using partial specialization:
namespace N1 { template <> class C1 <int> { int C2; }; }
// ...
void f () { N1::C1 <int>::C2 <3> & arg; } // Ouch.

(**) // Similarly.

--
Regards,
Buster.


这篇关于GCC 3.4很挑剔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆