Opened 4 years ago
#153 new defect
Compiler error when referencing a polymorphic type from within a polymorphic method which uses a trait whose methods operate on that same polymorphic type
Reported by: | dkobets | Owned by: | |
---|---|---|---|
Priority: | minor | Component: | cfa-cc |
Version: | 1.0 | Keywords: | |
Cc: |
Description
Example code:
an anonymous trait is created containing a method operating on a polymorphic type A
, and a polymorphic method bar
relying on this trait attempts to use A
by instantiating it. A compiler error is generated
forall (otype T) { struct A {}; } forall (otype T | {void foo(A(T));}) { void bar() { A(T) T; } } int main() {}
main.cfa: In function '_X3barQ1_0_0_5X16_operator_assignFBD0_BD0BD0X12_constructorFv_BD0X12_constructorFv_BD0BD0X11_destructorFv_BD0X3fooFv_S1A_BD0_Fv_1':
main.cfa:10:46: error: '_sizeof_S1A_Y1T_' undeclared (first use in this function)
void bar() {
main.cfa:10:46: note: each undeclared identifier is reported only once for each function it appears in
The same compiler error is generated when the trait is not anonymous
Removing the requirement on A
in the trait resolves the issue:
forall (otype T) { struct A {}; } forall (otype T | {void foo(T);}) { void bar() { A(T) T; } } int main() {}
using the -CFA
flag during compilation shows that the working version
contains the following snippet:
unsigned long int _sizeof_S1A_Y1T_ = 1; unsigned long int _alignof_S1A_Y1T_ = 1; __attribute__ ((aligned(8))) char _buf22[_sizeof_S1A_Y1T_];
whereas in the broken version, the same region of code is missing the first two lines, thus resulting in an undeclared identifier
error
__attribute__ ((aligned(8))) char _buf22[_sizeof_S1A_Y1T_];