This is an archive of the discontinued LLVM Phabricator instance.

Fix treatment of types defined in function prototype
ClosedPublic

Authored by sepavloff on Jun 14 2014, 9:28 AM.

Details

Summary

Types defined in function prototype are diagnosed earlier in C++ compilation.
They are put into declaration context where the prototype is introduced. Later on,
when FunctionDecl object is created, these types are moved into the function context.

This patch fixes PR19018 and PR18963.

Diff Detail

Repository
rL LLVM

Event Timeline

sepavloff updated this revision to Diff 10418.Jun 14 2014, 9:28 AM
sepavloff retitled this revision from to Fix treatment of types defined in function prototype.
sepavloff updated this object.
sepavloff edited the test plan for this revision. (Show Details)
sepavloff added a subscriber: Unknown Object (MLST).Jun 14 2014, 9:38 AM
rsmith accepted this revision.Jun 24 2014, 9:24 AM
rsmith edited edge metadata.

LGTM

test/SemaCXX/type-definition-in-specifier.cpp
44 ↗(On Diff #10418)

Does this still work if you put something more complex into the struct definition? (For instance, if it tries to reference a member of the surrounding struct, or if it has member functions, or similar.)

This revision is now accepted and ready to land.Jun 24 2014, 9:24 AM
sepavloff closed this revision.Jun 25 2014, 10:18 AM
sepavloff updated this revision to Diff 10839.

Closed by commit rL211718 (authored by @sepavloff).

Thank you for review.

2014-06-24 23:24 GMT+07:00 Richard Smith <richard@metafoo.co.uk>:

LGTM

Comment at: test/SemaCXX/type-definition-in-specifier.cpp:44
@@ +43,3 @@
+ void func4(struct t19018 {int qq;} x); expected-error{{cannot be
defined in a parameter type}}
+ void func5(struct {int qq;} x);
expected-error{{cannot be defined in
a parameter type}}

+};

Does this still work if you put something more complex into the struct
definition? (For instance, if it tries to reference a member of the
surrounding struct, or if it has member functions, or similar.)

It still works, corresponding testcases are added. However, access to a
member of the surrounding struct is resolved as for nested types, the code:

struct aaa {

int xx;
void func5(struct { int qq() { return xx; }; } x);

};

produces also a message:

error: use of non-static data member 'xx' of 'aaa' from nested type ''

I don't know if this behavior need to be fixed, as type defined in
prototype itself is erroneous.

Thanks,
--Serge