http://llvm.org/bugs/show_bug.cgi?id=15199
Bug ID: 15199
Summary: Different type conversion in ternary operator between
clang and gcc
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Classification: Unclassified
Consider the following snippet:
#include <cstdint>
#include <stdio.h>
const int64_t kint64max = ((int64_t)0x7FFFFFFFFFFFFFFFLL);
int main() {
double d = (double)kint64max;
int64_t v = d < kint64max ? d : kint64max;
printf("%.20f -> %ld\n", d, v);
return 0;
}
/tmp$ ~/build/llvm-opt/bin/clang++ -std=c++11 -o tt t.cc && ./tt
9223372036854775808.00000000000000000000 -> -9223372036854775808
/tmp$ g++ -std=c++0x -o tt t.cc && ./tt
9223372036854775808.00000000000000000000 -> 9223372036854775807
Changing this to:
int64_t v = d < kint64max ? (int64_t)d : kint64max;
/tmp$ ~/build/llvm-opt/bin/clang++ -std=c++11 -o tt t.cc && ./tt
9223372036854775808.00000000000000000000 -> 9223372036854775807
The question is whether clang or gcc is correct, or there is something
different I'm not understanding going on here. Chandler suggested I file a bug
and let the language lawyers take a shot :)
The AST for the original code from clang looks like this:
(ImplicitCastExpr 0x31628d0 <col:7, col:27> 'int64_t':'long'
<FloatingToIntegral>
(ConditionalOperator 0x31628a0 <col:7, col:27> 'double'
(BinaryOperator 0x31627e0 <col:7, col:11> '_Bool' '<'
(ImplicitCastExpr 0x3162798 <col:7> 'double' <LValueToRValue>
(DeclRefExpr 0x3162748 <col:7> 'double' lvalue Var 0x31625e0 'd'
'double'))
(ImplicitCastExpr 0x31627c8 <col:11> 'double' <IntegralToFloating>
(ImplicitCastExpr 0x31627b0 <col:11> 'int64_t':'long'
<LValueToRValue>
(DeclRefExpr 0x3162770 <col:11> 'const int64_t':'const long'
lvalue Var 0x31623d0 'kint64max' 'const int64_t':'const long'))))
(ImplicitCastExpr 0x3162858 <col:23> 'double' <LValueToRValue>
(DeclRefExpr 0x3162808 <col:23> 'double' lvalue Var 0x31625e0 'd'
'double'))
(ImplicitCastExpr 0x3162888 <col:27> 'double' <IntegralToFloating>
(ImplicitCastExpr 0x3162870 <col:27> 'int64_t':'long'
<LValueToRValue>
(DeclRefExpr 0x3162830 <col:27> 'const int64_t':'const long'
lvalue Var 0x31623d0 'kint64max' 'const int64_t':'const long')))))"))
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs