为什么海湾合作委员会声称我违反了"at least one argument for variadic macro",而我至少有一个论点?
Why does GCC claim I'm violating "at least one argument for variadic macro" when I have at least one argument?
以下是我用来重现此错误的示例代码:
#include <iostream>
#define TEST_2_ARG_MACRO_OVERLOAD(_1,_2,FUNC_NAME,...) FUNC_NAME
#define TEST_HELLO_IMPL(condition) do{
if(!(condition)) {
std::cout << "hello!" << std::endl;
}
} while(0)
#define TEST_HELLO_MESSAGE_IMPL(condition, message) do{
if(!(condition)) {
std::cout << "hello" << message << std::endl;
}
} while(0)
//Runs during runtime and debug
#define TEST_HELLO(...) TEST_2_ARG_MACRO_OVERLOAD(__VA_ARGS__, TEST_HELLO_MESSAGE_IMPL, TEST_HELLO_IMPL)(__VA_ARGS__)
int main()
{
auto x = 3 * (3);
TEST_HELLO(x >= 3);
}
带GCC x86-64 8.2的导螺杆内,使用:
-std=c++14 -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wpedantic -Werror
作为自变量,我得到以下错误:
<source>:24:22: error: ISO C++11 requires at least one argument for the "..." in a variadic macro [-Werror]
TEST_HELLO(x >= 3);
^
cc1plus: all warnings being treated as errors
Compiler returned: 1
然而,在宏观层面上,显然至少有一个论点。现在,我知道当我不启用此警告时,以及当我不将此警告作为错误启用时,会进行编译,但出于其他原因,我希望保留这些编译器标志(或至少保持相同的结果)。
为什么GCC声称我没有通过任何参数
问题实际上是TEST_2_ARG_MACRO_OVERLOAD
,错误消息有点误导。
该宏接受3个参数和...
,在ISO C++中,这意味着您必须至少传递4个参数,但实际上只传递3个。(参考:C++17[cpp.replace]/4)
TEST_HELLO
扩展为TEST_2_ARG_MACRO_OVERLOAD(x >= 3, TEST_HELLO_MESSAGE_IMPL, TEST_HELLO_IMPL)(x >= 3)
。
相关文章:
- "error: no matching function for call to"构造函数错误
- 表示"accepting anything for this template argument" C++概念的通配符
- 如何在C++中从两个单独的for循环中添加两个数组
- 在Linux for Windows上编译C++代码时出错
- 调用专用模板时出错"no matching function for call to [...]"
- 为什么我的for循环不能正确获取argv
- 为什么我不能在 FOR LOOP 中使用 i/10,C++?
- Arduino:for/while/if在void setup()或void loop()之前?——错误:之前需要不合格
- 在基于范围的for循环中使用结构化绑定声明
- 通过for循环使用用户输入填充列表
- 使用for循环检查数组中的重复项
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 正在使用for循环创建QScatterSerie
- Python中的for循环与C++有何不同
- std::memory_order for std::atomic:<T>:wait
- 在更改for循环的第三部分后,未使用for循环结果
- 在 for 循环中查找问题时遇到困难
- 为什么海湾合作委员会声称我违反了"at least one argument for variadic macro",而我至少有一个论点?
- _WIN32_WINNT macro for both win7 and winxp