删除“类型限定符”使用restrict关键字的函数的警告 [英] Get rid of "type qualifier" warnings on functions using the restrict keyword
问题描述
/ opt /我试图清除编译Blitz ++时出现的警告, local / include / blitz / tinyvec2.h:261:35:warning:在函数上忽略类型限定符return type [-Wignored-qualifiers]
/opt/local/include/blitz/tinyvec2.h:264:43:警告:函数上忽略类型限定符返回类型[-Wignored-qualifiers]
/opt/local/include/blitz/tinyvec2.h:267:40:warning:在函数上忽略类型限定符返回类型[-Wignored-qualifiers ]
<< etc>>
从这些成员函数( TinyVector
class)
T_numtype * restrict data()// line 261
{return data_; } // data是一个数据值数组的成员
const T_numtype * restrict data()const // line 264
{return data_; }
就我可以告诉我得到限制
关键字。注意:有些宏应该用 __ restrict __
(g ++理解)代替 restrict
。
我可以通过删除关键字来消除警告;然而,由于这应该是一个高性能的数字库,我不想失去任何编译器优化,限制
关键字允许。
我可以做些什么来抑制这些警告,而不是完全放弃 restrict
,并保持
__ restrict __
为什么 gcc
给你诊断。关键字用于表示传递给函数的两个指针不指向同一个对象,即。他们是独一无二的;改变一个不会影响另一个。这可以大大提高优化,但值得注意的是它不会影响函数的返回值。
没有理由在返回类型上应用 __ restrict __
。
上述 README 是由我写的,我使用 quotations 引起一些额外的关注,因为包含的信息对于手头的事情很重要。
使用gcc特定编译指示忽略警告
您可以要求 gcc
忽略与 -Wignored-qualifiers
匹配的诊断,方法是使用 诊断pragmas 。
>
这将忽略 -Wignored-qualifiers
启用的每个警告;
#pragma忽略GCC诊断-Wignored-qualifiers
b $ b
为选择区域忽略
c $ c> -Wignored-qualifiers 相关警告代码由 ...
... // warningings enabled
#pragma GCC诊断推送
#pragma忽略GCC诊断-Wignored-qualifiers
... //警告禁用这里
#pragma GCC诊断pop
... //警告再次启用
注:
- 通过
>-Wextra
,而不是-Wall
启用Wignored-qualifiersI'm trying to clean up warnings that I'm getting when compiling Blitz++ of the form:
/opt/local/include/blitz/tinyvec2.h:261:35: warning: type qualifiers ignored on function return type [-Wignored-qualifiers] /opt/local/include/blitz/tinyvec2.h:264:43: warning: type qualifiers ignored on function return type [-Wignored-qualifiers] /opt/local/include/blitz/tinyvec2.h:267:40: warning: type qualifiers ignored on function return type [-Wignored-qualifiers] <<etc.>>
From these kinds of member functions (of the
TinyVector
class)T_numtype * restrict data() // line 261 { return data_; } // data is a member that is an array of data values const T_numtype * restrict data() const // line 264 { return data_; }
As far as I can tell I am getting the warnings due to the
restrict
keyword. Note: there are macros that should replace therestrict
with__restrict__
(which g++ understands).I can get rid of the warnings by deleting the keywords; however, since this is supposed to be a high-performance numerical library, I don't want to lose any compiler optimizations that the
restrict
keywords are allowing.What can I do to suppress these warnings without just dropping the
restrict
's altogether, and while keeping-Wall
on?解决方案README
__restrict__
has no usage on return-types, which is exactly whygcc
is giving you the diagnostic. The keyword is used to signal that two pointers passed to a function doesn't point to the same object, ie. that they are unique; changing one will not affect the other. This can greatly improve optimizations, but it's worth noting that it won't affect the returned value of a function.There's no reason for you to apply
__restrict__
on the return type.The above README is written by me, I used quotations to draw some extra attention to it since the information contained is important to the matter at hand..
Ignore warning using gcc specific pragma
You could ask
gcc
to disregard diagnostics matching-Wignored-qualifiers
by using diagnostic pragmas.
Ignore it everywhere
This will ignore every warning that -Wignored-qualifiers
would enable;
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
Ignore it for a seleted area
This will ignore -Wignored-qualifiers
related warnings for the code replaced by ...
... // warnings enabled
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
... // warning disabled here
#pragma GCC diagnostic pop
... // warnings enabled again
Note: -Wignored-qualifiers
is enabled through -Wextra
, not -Wall
.
这篇关于删除“类型限定符”使用restrict关键字的函数的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!