是否可以禁用有关用户定义文字中缺少下划线的GCC警告? [英] Is it possible to disable GCC warning about missing underscore in user defined literal?

查看:91
本文介绍了是否可以禁用有关用户定义文字中缺少下划线的GCC警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void operator"" test( const char* str, size_t sz  )
{
    std::cout<<str<<" world";
}

int main()
{
    "hello"test;
    return 0;
}

在GCC 4.7中,这会生成警告:字面运算符后缀不带' _'为将来的标准化保留[默认启用]

In GCC 4.7, this generates "warning: literal operator suffixes not preceded by '_' are reserved for future standardization [enabled by default]"

我理解为什么会生成此警告,但GCC表示默认启用。

I understand why this warning is generated, but GCC says "enabled by default".

是否可以禁用此警告而不只是通过-w标志禁用所有警告?

Is it possible to disable this warning without just disabling all warnings via the -w flag?

推荐答案

在阅读了对该问题的几条评论后,我回顾了C ++ 11标准(非最终草案N3337)。

After reading several comments to this question, I reviewed the C++ 11 Standard (non-final draft N3337).

当我说我理解为什么这样做的时候产生警告。我误解了。
我认为该标准在技术上并不需要下划线,而只是一个建议(因此,警告而不是错误)。

When I said "I understand why this warning is generated" I was mistaken. I assumed that an underscore was not technically required by the standard, but just a recommendation (hence the warning rather than an error).

但是正如Nicol Bolas提出的那样,在谈论用户定义的文字时,该标准使用以下语言:

But as Nicol Bolas has brought up, the standard uses the following language when speaking about user defined literals:


保留不以下划线开头的文字后缀标识符以供将来标准化。 ; usrlit.suffix

" ;一些文字后缀标识符被保留以供将来标准化;参见[usrlit.suffix]。其文字操作符标识使用这样的文字后缀标识符的声明是不正确的,不需要诊断。 over.literal

"Some literal suffix identifiers are reserved for future standardization; see [usrlit.suffix]. A declaration whose literal-operator-id uses such a literal suffix identifier is ill-formed, no diagnostic required." over.literal

这类似于用于保留标识符和替代表示的语言。例如和,或,不是。我认为,这很清楚,实际上这本来不是警告,而是错误。

This is similar to the language used for reserved identifiers and the "alternative representations" such as "and", "or", "not". I think this makes it pretty clear that this shouldn't actually be a warning in the first place, but an error.

这可能不是 is问题的直接答案。可以禁用,但这对我来说已经足够了。

This may not be the direct answer to the question of "is it possible to disable", but it is answer enough for me.

这篇关于是否可以禁用有关用户定义文字中缺少下划线的GCC警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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