Oracle Solaris Studio 12.3的C++预处理器在扩展时会完全删除空白__VA_ARGS__.
有人可以在他们的系统上确认这种行为吗?它是一个已知的编译器错误吗?这个问题有没有解决方法?
为了说明,这是一个简单的测试程序,vaargs.c:
#include <stdio.h>
#define PRINT(...) printf("%s\n", #__VA_ARGS__)
int main()
{
PRINT(hello world);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
C预处理器按预期工作:
$ cc vaargs.c -o vaargs && ./vaargs
hello world
$ cc -V
cc: Sun C 5.12 SunOS_i386 2011/11/16
Run Code Online (Sandbox Code Playgroud)
但是C++预处理器删除了"hello"和"world"之间的空格:
$ CC vaargs.c -o vaargs && ./vaargs
helloworld
$ CC -V
CC: Sun C++ 5.12 SunOS_i386 2011/11/16
Run Code Online (Sandbox Code Playgroud) 源代码(在问题的最后)将引发我认为是Solaris Studio上的错误错误(而不是其他编译器).
为清楚起见,使用新行重新格式化了错误消息:
"overload.cpp", line 44: Error:
runGenEntries<std::vector<int>>(const GenEntryRuleDriven<int>&, const std::vector<int>&)
and
runGenEntries<std::vector<int>>(const GenEntryRulesDriven<int>&, const std::vector<int>&)
have same extern name
"__1cNrunGenEntries4nDstdGvector4Cin0AJallocator4Ci_____6FrkTArk1_v_".
1 Error(s) detected.
Run Code Online (Sandbox Code Playgroud)
注意两个函数runGenEntries的第一个参数如何只有一个字符(规则末尾的's')
当第一个参数是类型时,似乎会发生这种情况:
const typename GenEntryRulesDrivenType<typename InputsType::value_type>::type
Run Code Online (Sandbox Code Playgroud)
并且当第一个参数而不是类型时不会发生:
const typename GenEntryRulesDriven<typename InputsType::value_type>
Run Code Online (Sandbox Code Playgroud)
最终解决了相同的类型!
这是仅在Solaris上实现的一些模糊的C++规则的结果吗?或者,当它破坏符号时,这是一个Solaris Studio错误吗?
以下源代码可以在任何编译器上编译.
定义将激活引发错误的代码,或者激活应该产生相同结果的代码(但这次没有错误):
#include <iostream>
#include <vector>
template<typename T>
struct GenEntryRulesDriven
{
void foo() const
{
}
};
template<typename T>
struct GenEntryRuleDriven
{
void bar() const
{
}
std::string toto; // to have a different size than GenEntryRulesDriven
};
template <typename T> …Run Code Online (Sandbox Code Playgroud) 我试图"", line 1 : Illegal flag (-)在Sun Studio 12.3下追踪在Solaris 11.3(x64)上产生汇编错误的问题.Sun Studio编译器是一种特殊的地狱.
$ echo $CXX
/opt/solarisstudio12.3/bin/CC
$ cat test.cxx
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << argc << std::endl;
return 0;
}
$ $CXX -DNDEBUG -xO2 -native -template=no%extdef -m64 -Kpic -Wa,--divide -c test.cxx
Assembler:
"", line 1 : Illegal flag (-)
CC: fbe failed for test.cxx
Run Code Online (Sandbox Code Playgroud)
系统移除-xO2,-native,-m64,-Kpic,等...不能解决它.我在Mozilla发现了一个类似的报告,但删除调试符号并没有解决它.
汇编程序文件的第一行是.file ...(如下所示),因此我不清楚非法标志的来源.
我为什么要体验"", line …