<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - __is_trivial() gives wrong value when Clang generates code from AST file"
href="http://llvm.org/bugs/show_bug.cgi?id=19572">19572</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>__is_trivial() gives wrong value when Clang generates code from AST file
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>wluo@coverity.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=12448" name="attach_12448" title="A standalone reproducer.">attachment 12448</a> <a href="attachment.cgi?id=12448&action=edit" title="A standalone reproducer.">[details]</a></span>
A standalone reproducer.
I've attached a small standalone reproducer.
Clang 3.2 compiles it with no issue, but Clang 3.4 triggers the static_assert.
The problem exists only if I use -emit-ast and then compile from AST. If I skip
the -emit-ast step, things appear to work.
=== Clang 3.2 ===
$ ../clang32/bin/clang -c -std=c++11 test.cpp
$ ../clang32/bin/clang -emit-ast -std=c++11 test.cpp
$ ../clang32/bin/clang -c -std=c++11 test.ast
=== Clang 3.4 ===
$ ../clang34/bin/clang -c -std=c++11 test.cpp
$ ../clang34/bin/clang -c -std=c++11 -emit-ast test.cpp
$ ../clang34/bin/clang -c -std=c++11 test.ast
/home/wluo/space/test.cpp:21:5: error: static_assert failed "FOO"
static_assert(!__is_trivial(_ValueType), "FOO");
^ ~~~~~~~~~~~~~~~~~~~~~~~~~
/home/wluo/space/test.cpp:27:5: note: in instantiation of function template
specialization
'func<struct Data<const int> *>' requested here
func(table_start);
^
1 error generated.
=== Suggested fix ===
In Clang 3.2, QualType::isTrivialType() relies on
ClassDecl->hasTrivialDefaultConstructor(), but in Clang 3.4 it uses
!ClassDecl->hasNonTrivialDefaultConstructor().
It seems ClassDecl->hasNonTrivialDefaultConstructor() is returning false in
this case, which I don't think is correct. Data<const int> has a user-provided
default constructor, and according to C++ [class.ctor] one of the requirements
for the default trivial constructor is that it isn't user-provided.
The following change seems to fix the issue:
--- a/llvm-3.4/tools/clang/lib/AST/Type.cpp
+++ b/llvm-3.4/tools/clang/lib/AST/Type.cpp
@@ -1064,9 +1064,15 @@ bool QualType::isTrivialType(ASTContext &Context) const
{
// A trivial class is a class that has a default constructor,
// has no non-trivial default constructors, and is trivially
// copyable.
+#if 1
+ // See BZ xxxxx comment x for why we don't want to use
+ // hasNonTrivialDefaultConstructor().
+ return ClassDecl->isTrivial();
+#else
return ClassDecl->hasDefaultConstructor() &&
!ClassDecl->hasNonTrivialDefaultConstructor() &&
ClassDecl->isTriviallyCopyable();
+#endif
}
return true;</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>