<html>
<head>
<base href="https://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 --- - Objective-C++ to C++ Rewriter produces ill-formed C++11 code" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24344&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=v_THJPZXkmRJ5mL1pkFjQjVkegWag-_6TfpKzwtlF9E&s=eU5XMdtz4EM6xUkv0jQX_5FQGfDpMHy7UgB4H2LuDF8&e=">24344</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Objective-C++ to C++ Rewriter produces ill-formed C++11 code
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>charles_li@playstation.sony.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>Hello Clang developers,
I came across this bug when running Clang lit tests on test/Rewriter folder
with the default C++ standard dialect set to C++11.
When I ran the test, 32 tests failed.
The list is appended to the bottom.
It appears that when rewriting Objective-C++ to C++,
the rewriter will always generate C++03 code,
even when -std=C++11 mode is requested.
Here is a reduced test case:
/*************************************************/
@interface Foo {
int a;
}
@end
@implementation Foo
static void foo() {
}
@end
/*************************************************/
Rewriting this test to C++ then Compiling the C++ code produces the following.
$clang -cc1 -x objective-c++ -fms-extensions -rewrite-objc
-fobjc-runtime=macosx-fragile-10.5 t.mm -o t_gen.cpp -std=c++11
$clang -cc1 -Did="void*" -D"SEL=void*" -D"__declspec(X)=" t_gen.cpp -std=c++11
t_gen.cpp:104:5: warning: ISO C++11 does not allow conversion from string
literal to 'char *'
,{{"a", "i", __OFFSETOFIVAR__(struct Foo_IMPL, a)}
^
t_gen.cpp:104:10: warning: ISO C++11 does not allow conversion from string
literal to 'char *'
,{{"a", "i", __OFFSETOFIVAR__(struct Foo_IMPL, a)}
^
t_gen.cpp:104:15: error: non-constant-expression cannot be narrowed from type
'long long' to 'int' in initializer list
,{{"a", "i", __OFFSETOFIVAR__(struct Foo_IMPL, a)}
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t_gen.cpp:77:40: note: expanded from macro '__OFFSETOFIVAR__'
#define __OFFSETOFIVAR__(TYPE, MEMBER) ((long long) &((TYPE *)0)->MEMBER)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t_gen.cpp:104:15: note: insert an explicit cast to silence this issue
,{{"a", "i", __OFFSETOFIVAR__(struct Foo_IMPL, a)}
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static_cast<int>( )
t_gen.cpp:77:40: note: expanded from macro '__OFFSETOFIVAR__'
#define __OFFSETOFIVAR__(TYPE, MEMBER) ((long long) &((TYPE *)0)->MEMBER)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t_gen.cpp:124:34: warning: ISO C++11 does not allow conversion from string
literal to 'char *'
(struct _objc_class *)"Foo", 0, "Foo", 0,2, sizeof(struct _objc_class),
0, 0
^
t_gen.cpp:129:27: warning: ISO C++11 does not allow conversion from string
literal to 'char *'
&_OBJC_METACLASS_Foo, 0, "Foo", 0,1,sizeof(struct Foo_IMPL), (struct
_objc_ivar_list *)&_OBJC_INSTANCE_VARIABLES_Foo
^
4 warnings and 1 error generated.
I noticed in the generated C++ file, macro __OFFSETOFIVAR__ returns type “long
long”.
While the value being initialized is “int ivar_offset”.
/*****************************************************************/
#define __OFFSETOFIVAR__(TYPE, MEMBER) ((long long) &((TYPE *)0)->MEMBER)
struct _objc_ivar {
char *ivar_name;
char *ivar_type;
int ivar_offset;
};
static struct {
int ivar_count;
struct _objc_ivar ivar_list[1];
} _OBJC_INSTANCE_VARIABLES_Foo __attribute__ ((used, section ("__OBJC,
__instance_vars")))= {
1
,{{"a", "i", __OFFSETOFIVAR__(struct Foo_IMPL, a)}
}
};
/*****************************************************************/
Narrowing conversion inside an initializer list is unfortunately ill-form in
C++11 per [dcl.init.aggr] and [dcl.init.list].
Here is the full list of Clang Lit failures in the Rewriter folder that fail
due to the same reason.
Failing Tests (32):
Clang :: Rewriter/modern-write-bf-abi.mm
Clang :: Rewriter/objc-modern-property-bitfield.m
Clang :: Rewriter/property-dot-syntax.mm
Clang :: Rewriter/rewrite-block-literal-1.mm
Clang :: Rewriter/rewrite-block-pointer.mm
Clang :: Rewriter/rewrite-byref-in-nested-blocks.mm
Clang :: Rewriter/rewrite-byref-vars.mm
Clang :: Rewriter/rewrite-cast-ivar-modern-access.mm
Clang :: Rewriter/rewrite-elaborated-type.mm
Clang :: Rewriter/rewrite-foreach-in-block.mm
Clang :: Rewriter/rewrite-foreach-protocol-id.m
Clang :: Rewriter/rewrite-forward-class.m
Clang :: Rewriter/rewrite-forward-class.mm
Clang :: Rewriter/rewrite-ivar-use.m
Clang :: Rewriter/rewrite-modern-atautoreleasepool.mm
Clang :: Rewriter/rewrite-modern-block-ivar-call.mm
Clang :: Rewriter/rewrite-modern-class.mm
Clang :: Rewriter/rewrite-modern-default-property-synthesis.mm
Clang :: Rewriter/rewrite-modern-extern-c-func-decl.mm
Clang :: Rewriter/rewrite-modern-ivar-use.mm
Clang :: Rewriter/rewrite-modern-ivars-2.mm
Clang :: Rewriter/rewrite-modern-ivars.mm
Clang :: Rewriter/rewrite-modern-nested-ivar.mm
Clang :: Rewriter/rewrite-modern-throw.m
Clang :: Rewriter/rewrite-nested-blocks-1.mm
Clang :: Rewriter/rewrite-nested-blocks.mm
Clang :: Rewriter/rewrite-nested-ivar.mm
Clang :: Rewriter/rewrite-property-attributes.mm
Clang :: Rewriter/rewrite-property-set-cfstring.mm
Clang :: Rewriter/rewrite-protocol-property.mm
Clang :: Rewriter/rewrite-user-defined-accessors.mm
Clang :: Rewriter/rewrite-vararg.m
Expected Passes : 112
Unexpected Failures: 32</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>