[LLVMbugs] [Bug 10291] New: clang asserts when comparing different types inside a throw inside a class template

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 6 20:52:52 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10291

           Summary: clang asserts when comparing different types inside a
                    throw inside a class template
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: tziltzal at y7mail.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


... pretty weird situation, but the following example causes clang to assert on
comparing different types:

template<typename T>
class X
{
public:

    X() : i(0) { } 

    void foo()
    {   
        throw 
            i == 0u ? // this causes the assertion
            5 : 6;
    }   

private:
    int i;
};

int main()
{
    X<int> x;
}

the output is:

clang: /usr/src/llvm/tools/clang/lib/Sema/SemaChecking.cpp:2810:
void<unnamed>::AnalyzeComparison(clang::Sema&, clang::BinaryOperator*):
Assertion `S.Context.hasSameUnqualifiedType(T, E->getRHS()->getType()) &&
"comparison with mismatched types"' failed.
0  clang           0x0000000001bd4f3f
1  clang           0x0000000001bd5a7a
2  libpthread.so.0 0x000000370780eeb0
3  libc.so.6       0x0000003706c330c5 gsignal + 53
4  libc.so.6       0x0000003706c34a76 abort + 390
5  libc.so.6       0x0000003706c2b905 __assert_fail + 245
6  clang           0x00000000009d753e
7  clang           0x00000000009d7611
8  clang           0x00000000009d709e
9  clang           0x00000000009d6f7a
10 clang           0x0000000000ad38d0
clang::Sema::ActOnFinishFullExpr(clang::Expr*) + 144
11 clang           0x0000000000932c91
clang::Parser::ParseExprStatement(clang::ParsedAttributes&) + 129
12 clang           0x000000000092f00b
clang::Parser::ParseStatementOrDeclaration(clang::ASTOwningVector<clang::Stmt*,
32u>&, bool) + 2875
13 clang           0x000000000092c23e
clang::Parser::ParseCompoundStatementBody(bool) + 1742
14 clang           0x000000000092c9e8
clang::Parser::ParseFunctionStatementBody(clang::Decl*,
clang::Parser::ParseScope&) + 168
15 clang           0x000000000094b249
clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) + 457
16 clang           0x000000000094afe9
clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) + 137
17 clang           0x00000000009699d4
clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, unsigned int,
clang::Decl*) + 2404
18 clang           0x000000000096ade0
clang::Parser::ParseClassSpecifier(clang::tok::TokenKind,
clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo
const&, clang::AccessSpecifier, bool) + 4432
19 clang           0x0000000000957240
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&,
clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier,
clang::Parser::DeclSpecContext) + 1408
20 clang           0x0000000000933b4d
clang::Parser::ParseSingleDeclarationAfterTemplate(unsigned int,
clang::Parser::ParsedTemplateInfo const&,
clang::Parser::ParsingDeclRAIIObject&, clang::SourceLocation&,
clang::AccessSpecifier) + 765
21 clang           0x00000000009372d2
clang::Parser::ParseTemplateDeclarationOrSpecialization(unsigned int,
clang::SourceLocation&, clang::AccessSpecifier) + 706
22 clang           0x000000000095bb8a
clang::Parser::ParseDeclaration(clang::ASTOwningVector<clang::Stmt*, 32u>&,
unsigned int, clang::SourceLocation&,
clang::Parser::ParsedAttributesWithRange&) + 522
23 clang           0x000000000094581b
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::Parser::ParsingDeclSpec*) + 603
24 clang           0x00000000009464ec
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 156
25 clang           0x000000000091b33d clang::ParseAST(clang::Sema&, bool) + 205
26 clang           0x00000000007bc534 clang::CodeGenAction::ExecuteAction() +
68
27 clang           0x00000000006b0d43
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 371
28 clang           0x000000000068923d
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1181
29 clang           0x000000000067dc7b cc1_main(char const**, char const**, char
const*, void*) + 779
30 clang           0x00000000006881b3 main + 7347
31 libc.so.6       0x0000003706c1ee5d __libc_start_main + 253
32 clang           0x000000000067d789
Stack dump:
0.      Program arguments: /usr/local/bin/clang -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name
test.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose
-mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version
2.20.51.0.7 -momit-leaf-frame-pointer -coverage-file
CMakeFiles/test.dir/test.cpp.o -resource-dir /usr/local/bin/../lib/clang/3.0
-fdeprecated-macro -ferror-limit 19 -fmessage-length 237 -fcxx-exceptions
-fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o
CMakeFiles/test.dir/test.cpp.o -x c++ /home/user/Sources/test/test.cpp 
1.      /home/user/Sources/test/test.cpp:13:5: current parser token '}'
2.      /home/user/Sources/test/test.cpp:2:1: parsing struct/union/class body
'X'
3.      /home/user/Sources/test/test.cpp:9:5: parsing function body 'foo'
4.      /home/user/Sources/test/test.cpp:9:5: in compound statement ('{}')
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal 2 (use -v to see
invocation)


if X isn't a template class, or you change 'throw' to be a different expression
(e.g. int x = ) or make sure that == compares identical types, it will compile
fine...

uname -a returns:

Linux fedora-host 2.6.35.13-92.fc14.x86_64 #1 SMP Sat May 21 17:26:25 UTC 2011
x86_64 x86_64 x86_64 GNU/Linux

clang --version returns:

clang version 3.0 (trunk 134577)
Target: x86_64-unknown-linux-gnu
Thread model: posix

clang/llvm were compiled with --enable-optimized.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list