2016-01-03 55 views
3

我真的试图用升压单元测试框架,这里是我的测试模块看起来像提升运算符<<是ambigious

#define BOOST_TEST_MODULE NodeTest 
#include <boost/test/unit_test.hpp> 
#include "Node.h" 

BOOST_AUTO_TEST_CASE(constructorsTest) 
{ 
    Node tc0; 
    BOOST_CHECK_EQUAL(tc0.getFrequency(), 0); 
    BOOST_CHECK_EQUAL(tc0.getLeftChild(), nullptr); // 1 // 
    BOOST_CHECK_EQUAL(tc0.getRightChild(), nullptr); 

} 

编译时,我得到一个错误

操作< < is ambigious

in print_helper.h。我究竟做错了什么?

+0

这个问题时,升压输出'nullptr'使用'print_log_value'帮手。而且,我想,'clang ++'无法用segfault编译代码示例。有趣。 – soon

回答

1

TL; DR:不能使用nullptrstd::cout(见this答案的解释),但是打印时,您可以使用以下workaround

BOOST_TEST_DONT_PRINT_LOG_VALUE(std::nullptr_t) 

没有直接关系的问题,但包含一些有趣的研究。铛++失败,段错误编译如下代码:

#include <ios> 
#include <boost/test/tools/detail/print_helper.hpp> 
#include <iostream> 

int main() 
{ 
    boost::test_tools::tt_detail::print_log_value<std::nullptr_t>{}(std::cout, nullptr); 
    return 0; 
} 

错误输出:出现

$ make 
-- Configuring done 
-- Generating done 
-- Build files have been written to: /home/soon/Src/C++/main 
Scanning dependencies of target main 
[ 50%] Building CXX object CMakeFiles/main.dir/main1.cpp.o 
#0 0x7fa1274006b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/bin/../lib/libLLVM.so.3.7+0x5686b0) 
#1 0x7fa1273ff491 (/usr/bin/../lib/libLLVM.so.3.7+0x567491) 
#2 0x7fa126c8bd60 __restore_rt (/usr/bin/../lib/libpthread.so.0+0x10d60) 
#3 0x13c09ad (/usr/bin/clang-3.7+0x13c09ad) 
#4 0x13ca17d (/usr/bin/clang-3.7+0x13ca17d) 
#5 0x13ca57e (/usr/bin/clang-3.7+0x13ca57e) 
#6 0x13c8ee3 (/usr/bin/clang-3.7+0x13c8ee3) 
#7 0x13c7dd5 (/usr/bin/clang-3.7+0x13c7dd5) 
#8 0x13c836e (/usr/bin/clang-3.7+0x13c836e) 
#9 0x13c8967 (/usr/bin/clang-3.7+0x13c8967) 
#10 0x13c837f (/usr/bin/clang-3.7+0x13c837f) 
#11 0x13c8967 (/usr/bin/clang-3.7+0x13c8967) 
#12 0x13c837f (/usr/bin/clang-3.7+0x13c837f) 
#13 0x13c9a4b (/usr/bin/clang-3.7+0x13c9a4b) 
#14 0x13c9da8 (/usr/bin/clang-3.7+0x13c9da8) 
#15 0x13cce69 (/usr/bin/clang-3.7+0x13cce69) 
#16 0x13c4386 (/usr/bin/clang-3.7+0x13c4386) 
#17 0x13c64d1 (/usr/bin/clang-3.7+0x13c64d1) 
#18 0x13c42a1 (/usr/bin/clang-3.7+0x13c42a1) 
#19 0x13c593f (/usr/bin/clang-3.7+0x13c593f) 
#20 0x13c7269 (/usr/bin/clang-3.7+0x13c7269) 
#21 0x13c7155 (/usr/bin/clang-3.7+0x13c7155) 
#22 0x13c7490 (/usr/bin/clang-3.7+0x13c7490) 
#23 0x13cc760 (/usr/bin/clang-3.7+0x13cc760) 
#24 0x69c712 clang::CodeGen::CodeGenModule::getMangledName(clang::GlobalDecl) (/usr/bin/clang-3.7+0x69c712) 
#25 0x6a8813 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/usr/bin/clang-3.7+0x6a8813) 
#26 0x6dd2d9 (/usr/bin/clang-3.7+0x6dd2d9) 
#27 0x6a94b8 (/usr/bin/clang-3.7+0x6a94b8) 
#28 0x9915d3 (/usr/bin/clang-3.7+0x9915d3) 
#29 0x98c50c (/usr/bin/clang-3.7+0x98c50c) 
#30 0xfc5035 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool) (/usr/bin/clang-3.7+0xfc5035) 
#31 0xdc2323 clang::Sema::MarkFunctionReferenced(clang::SourceLocation, clang::FunctionDecl*, bool) (/usr/bin/clang-3.7+0xdc2323) 
#32 0xd33aa1 clang::Sema::BuildCXXConstructExpr(clang::SourceLocation, clang::QualType, clang::CXXConstructorDecl*, bool, llvm::MutableArrayRef<clang::Expr*>, bool, bool, bool, bool, unsigned int, clang::SourceRange) (/usr/bin/clang-3.7+0xd33aa1) 
#33 0xd33ba9 clang::Sema::BuildCXXConstructExpr(clang::SourceLocation, clang::QualType, clang::CXXConstructorDecl*, llvm::MutableArrayRef<clang::Expr*>, bool, bool, bool, bool, unsigned int, clang::SourceRange) (/usr/bin/clang-3.7+0xd33ba9) 
#34 0xe5726c clang::InitializationSequence::Perform(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::QualType*) (/usr/bin/clang-3.7+0xe5726c) 
#35 0xe10277 (/usr/bin/clang-3.7+0xe10277) 
#36 0xe106d9 clang::Sema::BuildTypeTrait(clang::TypeTrait, clang::SourceLocation, llvm::ArrayRef<clang::TypeSourceInfo*>, clang::SourceLocation) (/usr/bin/clang-3.7+0xe106d9) 
#37 0xf9b94b (/usr/bin/clang-3.7+0xf9b94b) 
#38 0xf9ef4e (/usr/bin/clang-3.7+0xf9ef4e) 
#39 0xfa1529 (/usr/bin/clang-3.7+0xfa1529) 
#40 0xf9eed4 (/usr/bin/clang-3.7+0xf9eed4) 
#41 0xfa789e (/usr/bin/clang-3.7+0xfa789e) 
#42 0xfaafe7 (/usr/bin/clang-3.7+0xfaafe7) 
#43 0xf99028 (/usr/bin/clang-3.7+0xf99028) 
#44 0xf99e81 (/usr/bin/clang-3.7+0xf99e81) 
#45 0xf99fe3 clang::Sema::SubstType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName) (/usr/bin/clang-3.7+0xf99fe3) 
#46 0xfb675d clang::Sema::SubstBaseSpecifiers(clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&) (/usr/bin/clang-3.7+0xfb675d) 
#47 0xfb74dd clang::Sema::InstantiateClass(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/usr/bin/clang-3.7+0xfb74dd) 
#48 0xfb85ce clang::Sema::InstantiateClassTemplateSpecialization(clang::SourceLocation, clang::ClassTemplateSpecializationDecl*, clang::TemplateSpecializationKind, bool) (/usr/bin/clang-3.7+0xfb85ce) 
#49 0xfe3b25 clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::TypeDiagnoser&) (/usr/bin/clang-3.7+0xfe3b25) 
#50 0xfe3d8f clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::TypeDiagnoser&) (/usr/bin/clang-3.7+0xfe3d8f) 
#51 0xc61190 clang::Sema::RequireCompleteDeclContext(clang::CXXScopeSpec&, clang::DeclContext*) (/usr/bin/clang-3.7+0xc61190) 
#52 0xdc8c75 clang::Sema::BuildQualifiedDeclarationNameExpr(clang::CXXScopeSpec&, clang::DeclarationNameInfo const&, bool, clang::TypeSourceInfo**) (/usr/bin/clang-3.7+0xdc8c75) 
#53 0xfad9cd (/usr/bin/clang-3.7+0xfad9cd) 
#54 0xfadb0d (/usr/bin/clang-3.7+0xfadb0d) 
#55 0xf9ec9e (/usr/bin/clang-3.7+0xf9ec9e) 
#56 0xfa789e (/usr/bin/clang-3.7+0xfa789e) 
#57 0xfaafe7 (/usr/bin/clang-3.7+0xfaafe7) 
#58 0xfabc2e (/usr/bin/clang-3.7+0xfabc2e) 
#59 0xfac335 (/usr/bin/clang-3.7+0xfac335) 
#60 0xf99586 (/usr/bin/clang-3.7+0xf99586) 
#61 0xf99673 (/usr/bin/clang-3.7+0xf99673) 
#62 0xf99e81 (/usr/bin/clang-3.7+0xf99e81) 
#63 0xf99fe3 clang::Sema::SubstType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName) (/usr/bin/clang-3.7+0xf99fe3) 
#64 0xf966e1 clang::Sema::SubstParmVarDecl(clang::ParmVarDecl*, clang::MultiLevelTemplateArgumentList const&, int, llvm::Optional<unsigned int>, bool) (/usr/bin/clang-3.7+0xf966e1) 
#65 0xf97533 (/usr/bin/clang-3.7+0xf97533) 
#66 0xf9d061 clang::Sema::SubstFunctionDeclType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, clang::CXXRecordDecl*, unsigned int) (/usr/bin/clang-3.7+0xf9d061) 
#67 0xfbb111 clang::TemplateDeclInstantiator::VisitDecl(clang::Decl*) (/usr/bin/clang-3.7+0xfbb111) 
#68 0xfca77a clang::TemplateDeclInstantiator::VisitCXXMethodDecl(clang::CXXMethodDecl*, clang::TemplateParameterList*, bool) (/usr/bin/clang-3.7+0xfca77a) 
#69 0xfc1735 clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&) (/usr/bin/clang-3.7+0xfc1735) 
#70 0xf87a58 clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> const*, bool) (/usr/bin/clang-3.7+0xf87a58) 
#71 0xf91672 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool) (/usr/bin/clang-3.7+0xf91672) 
#72 0xee2c0f clang::Sema::AddTemplateOverloadCandidate(clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool) (/usr/bin/clang-3.7+0xee2c0f) 
#73 0x60fc73 _init (/usr/bin/clang-3.7+0x60fc73) 
#74 0xe5ed47 clang::InitializationSequence::InitializeFrom(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool) (/usr/bin/clang-3.7+0xe5ed47) 
#75 0xcf509f clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool, bool) (/usr/bin/clang-3.7+0xcf509f) 
#76 0xad5e5f clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/usr/bin/clang-3.7+0xad5e5f) 
#77 0xae31f2 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/usr/bin/clang-3.7+0xae31f2) 
#78 0xae6101 clang::Parser::ParseSimpleDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, bool, clang::Parser::ForRangeInit*) (/usr/bin/clang-3.7+0xae6101) 
#79 0xae63b6 clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) (/usr/bin/clang-3.7+0xae63b6) 
#80 0xb3beef clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) (/usr/bin/clang-3.7+0xb3beef) 
#81 0xb3c11b clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*) (/usr/bin/clang-3.7+0xb3c11b) 
#82 0xb40c3e clang::Parser::ParseCompoundStatementBody(bool) (/usr/bin/clang-3.7+0xb40c3e) 
#83 0xb433c6 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/usr/bin/clang-3.7+0xb433c6) 
#84 0xaca232 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/usr/bin/clang-3.7+0xaca232) 
#85 0xb4e420 clang::Parser::ParseSingleDeclarationAfterTemplate(unsigned int, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) (/usr/bin/clang-3.7+0xb4e420) 
#86 0xb4f13d clang::Parser::ParseTemplateDeclarationOrSpecialization(unsigned int, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) (/usr/bin/clang-3.7+0xb4f13d) 
#87 0xb4f42f clang::Parser::ParseDeclarationStartingWithTemplate(unsigned int, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) (/usr/bin/clang-3.7+0xb4f42f) 
#88 0xae6527 clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) (/usr/bin/clang-3.7+0xae6527) 
#89 0xacd401 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/usr/bin/clang-3.7+0xacd401) 
#90 0xaf2a45 clang::Parser::ParseInnerNamespace(std::vector<clang::SourceLocation, std::allocator<clang::SourceLocation> >&, std::vector<clang::IdentifierInfo*, std::allocator<clang::IdentifierInfo*> >&, std::vector<clang::SourceLocation, std::allocator<clang::SourceLocation> >&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/usr/bin/clang-3.7+0xaf2a45) 
#91 0xaf351c clang::Parser::ParseNamespace(unsigned int, clang::SourceLocation&, clang::SourceLocation) (/usr/bin/clang-3.7+0xaf351c) 
#92 0xae657d clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) (/usr/bin/clang-3.7+0xae657d) 
#93 0xacd401 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/usr/bin/clang-3.7+0xacd401) 
#94 0xaf2a45 clang::Parser::ParseInnerNamespace(std::vector<clang::SourceLocation, std::allocator<clang::SourceLocation> >&, std::vector<clang::IdentifierInfo*, std::allocator<clang::IdentifierInfo*> >&, std::vector<clang::SourceLocation, std::allocator<clang::SourceLocation> >&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/usr/bin/clang-3.7+0xaf2a45) 
#95 0xaf351c clang::Parser::ParseNamespace(unsigned int, clang::SourceLocation&, clang::SourceLocation) (/usr/bin/clang-3.7+0xaf351c) 
#96 0xae657d clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) (/usr/bin/clang-3.7+0xae657d) 
#97 0xacd401 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/usr/bin/clang-3.7+0xacd401) 
#98 0xacddb9 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) (/usr/bin/clang-3.7+0xacddb9) 
#99 0xac1ea3 clang::ParseAST(clang::Sema&, bool, bool) (/usr/bin/clang-3.7+0xac1ea3) 
#100 0x915fa6 clang::FrontendAction::Execute() (/usr/bin/clang-3.7+0x915fa6) 
#101 0x8ec629 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/bin/clang-3.7+0x8ec629) 
#102 0x98bab3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/bin/clang-3.7+0x98bab3) 
#103 0x657208 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang-3.7+0x657208) 
#104 0x65265e main (/usr/bin/clang-3.7+0x65265e) 
#105 0x7fa12635f610 __libc_start_main (/usr/bin/../lib/libc.so.6+0x20610) 
#106 0x655279 _start (/usr/bin/clang-3.7+0x655279) 
Stack dump: 
0. Program arguments: /usr/bin/clang-3.7 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -main-file-name main1.cpp -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -momit-leaf-frame-pointer -g -dwarf-column-info -coverage-file /home/soon/Src/C++/main/CMakeFiles/main.dir/main1.cpp.o -resource-dir /usr/bin/../lib/clang/3.7.0 -D ACMP_DEBUG -D JUDGE_MIPT_DEBUG -D SOON_ACM_DEBUG -D SOON_ACM_TIMUS_DEBUG -D SOON_DEBUG -D SOON_GATE_DEBUG -D _GLIBCXX_USE_NANOSLEEP -I /usr/include/opencv -I /usr/include/python3.3m/ -I /usr/include/opencv -internal-isystem /usr/bin/../include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.7.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wall -W -Weffc++ -pedantic -std=c++1y -fdeprecated-macro -fdebug-compilation-dir /home/soon/Src/C++/main -ferror-limit 19 -fmessage-length 91 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o CMakeFiles/main.dir/main1.cpp.o -x c++ /home/soon/Src/C++/main/main1.cpp 
1. /usr/bin/../include/c++/v1/__mutex_base:381:38: current parser token ';' 
2. /usr/bin/../include/c++/v1/__mutex_base:23:1 <Spelling=/usr/bin/../include/c++/v1/__config:386:37>: parsing namespace 'std' 
3. /usr/bin/../include/c++/v1/__mutex_base:23:1 <Spelling=/usr/bin/../include/c++/v1/__config:386:59>: parsing namespace '__1' 
4. /usr/bin/../include/c++/v1/__mutex_base:375:1: parsing function body 'wait_for' 
5. /usr/bin/../include/c++/v1/__mutex_base:375:1: in compound statement ('{}') 
6. /usr/bin/../include/c++/v1/chrono:471:9: LLVM IR generation of declaration 'std::__1::chrono::duration<long double, std::__1::ratio<1, 1000000000> >::duration' 
clang-3.7: error: unable to execute command: Segmentation fault (core dumped) 
clang-3.7: error: clang frontend command failed due to signal (use -v to see invocation) 
clang version 3.7.0 (tags/RELEASE_370/final) 
Target: x86_64-unknown-linux-gnu 
Thread model: posix 
clang-3.7: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. 
clang-3.7: note: diagnostic msg: 
******************** 

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: 
Preprocessed source(s) and associated run script(s) are located at: 
clang-3.7: note: diagnostic msg: /tmp/main1-afdf7b.cpp 
clang-3.7: note: diagnostic msg: /tmp/main1-afdf7b.sh 
clang-3.7: note: diagnostic msg: 

******************** 
CMakeFiles/main.dir/build.make:62: recipe for target 'CMakeFiles/main.dir/main1.cpp.o' failed 
make[2]: *** [CMakeFiles/main.dir/main1.cpp.o] Error 254 
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/main.dir/all' failed 
make[1]: *** [CMakeFiles/main.dir/all] Error 2 
Makefile:83: recipe for target 'all' failed 
make: *** [all] Error 2 

$ clang++ --version 
clang version 3.7.0 (tags/RELEASE_370/final) 
Target: x86_64-unknown-linux-gnu 
Thread model: posix