Summary: | implement C++0x alias-declaration | ||
---|---|---|---|
Product: | gcc | Reporter: | Jason Merrill <jason> |
Component: | c++ | Assignee: | Dodji Seketeli <dodji> |
Status: | RESOLVED FIXED | ||
Severity: | enhancement | CC: | 3dw4rd, dodji, flast, gcc-bugs, hyounes, illissius, jacob.benoit.1, jason, j_d_cranch, louiskenzo, marc.coiffier, miles, pinskia, piotr.rak, vincenzo.innocente, webrown.cpp, yacwroy, zeratul976 |
Priority: | P3 | ||
Version: | 4.6.0 | ||
Target Milestone: | 4.7.0 | ||
See Also: | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69481 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2010-08-11 00:30:26 | |
Bug Depends on: | |||
Bug Blocks: | 45866 | ||
Attachments: |
initial incomplete patch
make use of alias-declarations in libstdc++ |
Description
Jason Merrill
2010-07-28 19:12:25 UTC
Created attachment 21341 [details]
initial incomplete patch
Corresponding paper, for reference: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2258.pdf Vincenzo is interested, let's add him in CC. I was trying out this patch to see whether it might be usable to me, just as a preview. Firstly: Is this patch at a stage where it could be possible to complete a make/install, or am I jumping the gun? I don't want to update the patch (at least not without confirmation), but in case anyone else wants to try it as is, I believe that "parser.c" line 13496: if (at_class_scope () || template_parm_scope_p ()) should be changed to: if (at_class_scope_p () || template_parm_scope_p ()) (otherwise it doesn't compile). I got an ICE trying to make GCC on a SVN trunk checkout yesterday after (manually) patching with this (it only failed on building the libs). I can supply details if you want, but I guess this patch is outdated now? I stopped working on it before it was usable at all, it's just here in case someone wants to use it as a starting point. *** Bug 42085 has been marked as a duplicate of this bug. *** Mine A candidate patch extending the patch attached in the first comment and allegedly implementing the feature was posted to http://gcc.gnu.org/ml/gcc-patches/2011-10/msg02494.html. If some people have self contained test cases, I'd be interested. I don't have any self-contained tests but there are a number of TODOs in libstdc++ which indicate places that should use a template alias when available - I'll try the patch and revisit those TODOs using the patch of comment 8 in the example below I get $ c++ -std=gnu++0x -c talias.cc $ c++ -std=gnu++0x -c talias.cc -DALIAS talias.cc: In instantiation of ‘Bar::D<T> Bar::d() [with T = int]’: talias.cc:44:19: required from here talias.cc:34:23: error: no matching function for call to ‘Bar::D<int>::D(Bar::A<int>)’ talias.cc:34:23: note: candidates are: talias.cc:19:5: note: Bar::D<T>::D(const Bar::A<T>&) [with T = int; Bar::A<T> = Foo<int>] talias.cc:19:5: note: no known conversion for argument 1 from ‘Bar::A<int> {aka Foo<int>}’ to ‘Bar::A<int>& {aka Foo<int>&}’ talias.cc:15:5: note: Bar::D<T>::D() [with T = int] talias.cc:15:5: note: candidate expects 0 arguments, 1 provided talias.cc:14:10: note: constexpr Bar::D<int>::D(const Bar::D<int>&) talias.cc:14:10: note: no known conversion for argument 1 from ‘Bar::A<int> {aka Foo<int>}’ to ‘const Bar::D<int>&’ talias.cc:14:10: note: constexpr Bar::D<int>::D(Bar::D<int>&&) talias.cc:14:10: note: no known conversion for argument 1 from ‘Bar::A<int> {aka Foo<int>}’ to ‘Bar::D<int>&&’ otherwise the patch looks fine (i.e. no other problem found so far :-) template<typename T> struct Foo { explicit Foo(char *im) : m(im){} char * m; }; struct Bar { template<typename T> using A = Foo<T>; template<typename T> struct D { D() {} #ifndef ALIAS D(Foo<T> const & ia) : a(ia) {} #else D(A<T> const & ia) : a(ia) {} #endif A<T> a; }; template<typename T> A<T> a() { return A<T>(m_i); } template<typename T> D<T> d() { return D<T>(a<T>()); } char m_i[10000]; }; Bar b; Bar::D<int> bar() { return b.d<int>(); } the example in comment 10 compiles fine if I add a move constructor D(A<T> && ia) : a(ia) {} or a "by value constructor" D(A<T> ia) : a(ia) {} "vincenzo.innocente at cern dot ch" <gcc-bugzilla@gcc.gnu.org> a écrit: > --- Comment #10 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2011-10-31 16:06:41 UTC --- > using the patch of comment 8 in the example below I get Thank you for testing the patch. Just FYI, I have updated it and posted a newer, hopefully better version to gcc-patches[1]. It happens to compile your example now. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg00747.html Author: dodji Date: Mon Nov 7 21:28:50 2011 New Revision: 181118 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181118 Log: PR c++/45114 - Support C++11 alias-declaration gcc/cp/ * cp-tree.h (TYPE_DECL_ALIAS_P, TYPE_ALIAS_P) (DECL_TYPE_TEMPLATE_P, DECL_ALIAS_TEMPLATE_P): New accessor macros. (TYPE_TEMPLATE_INFO): Get template info of an alias template specializations from its TYPE_DECL. (SET_TYPE_TEMPLATE_INFO): Set template info of alias template specializations into its TYPE_DECL. (DECL_CLASS_TEMPLATE_P): Re-write using the new DECL_TYPE_TEMPLATE_P. (enum cp_decl_spec): Add new ds_alias enumerator. (alias_type_or_template_p, alias_template_specialization_p): Declare new functions. * parser.c (cp_parser_alias_declaration): New static function. (cp_parser_check_decl_spec): Add "using" name for the `alias' declspec. (cp_parser_type_name): Update comment. Support simple-template-id representing alias template specializations in c++0x mode. (cp_parser_qualifying_entity): Update comment. Use cp_parser_type_name. (cp_parser_block_declaration): Handle alias-declaration in c++11. Update comment. (cp_parser_template_id): Handle specializations of alias templates. (cp_parser_member_declaration): Add alias-declaration production to comment. Support alias-declarations. (cp_parser_template_declaration_after_export): Handle alias templates in c++11. * decl.c (make_typename_type, make_unbound_class_template): Accept alias templates. (grokdeclarator): Set TYPE_DECL_ALIAS_P on alias declarations. * decl2.c (grokfield): Move template creation after setting up the TYPE_DECL of the alias, so that the TEMPLATE_DECL of the alias template actually carries the right type-id of the alias declaration. * pt.c (alias_type_or_template_p) (alias_template_specialization_p): Define new public functions. (maybe_process_partial_specialization): Reject partial specializations of alias templates. (primary_template_instantiation_p): Consider alias template instantiations. (push_template_decl_real): Assert that TYPE_DECLs of alias templates are different from those of class template. Store template info onto the TYPE_DECL of the alias template. (convert_template_argument): Strip aliases from template arguments. (lookup_template_class_1): Handle the creation of the specialization of an alias template. (tsubst_decl): Create a substituted copy of the TYPE_DECL of an member alias template. (tsubst): Handle substituting into the type of an alias template. Handle substituting UNBOUND_CLASS_TEMPLATE into BOUND_TEMPLATE_TEMPLATE_PARM. (do_type_instantiation): Better diagnostics when trying to explicitely instantiate a non-class template. * search.c (lookup_field_1, lookup_field_r): Support looking up alias templates. * semantics.c (finish_template_type): For instantiations of alias templates, return the TYPE_DECL of the actual alias and not the one of the aliased type. * error.c (dump_alias_template_specialization): New static function. (dump_type): Handle printing of alias templates and their specializations. templates. (dump_aggr_type): For specialization of alias templates, fetch arguments from the right place. (dump_decl): Print an alias-declaration like `using decl = type;' (dump_template_decl): Support printing of alias templates. gcc/testsuite/ * g++.dg/cpp0x/alias-decl-0.C: New test case. * g++.dg/cpp0x/alias-decl-1.C: Likewise. * g++.dg/cpp0x/alias-decl-3.C: Likewise. * g++.dg/cpp0x/alias-decl-4.C: Likewise. * g++.dg/cpp0x/alias-decl-6.C: Likewise. * g++.dg/cpp0x/alias-decl-7.C: Likewise. * g++.dg/cpp0x/alias-decl-8.C: Likewise. * g++.dg/cpp0x/alias-decl-9.C: Likewise. * g++.dg/cpp0x/alias-decl-10.C: Likewise. * g++.dg/ext/alias-decl-attr1.C: Likewise. * g++.dg/ext/alias-decl-attr2.C: Likewise. * g++.dg/ext/alias-decl-attr3.C: Likewise. * g++.dg/ext/alias-decl-attr4.C: Likewise. Added: trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-0.C trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-1.C trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-10.C trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-2.C trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-3.C trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-4.C trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-5.C trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-6.C trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-7.C trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-8.C trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-9.C trunk/gcc/testsuite/g++.dg/ext/alias-decl-attr1.C trunk/gcc/testsuite/g++.dg/ext/alias-decl-attr2.C trunk/gcc/testsuite/g++.dg/ext/alias-decl-attr3.C trunk/gcc/testsuite/g++.dg/ext/alias-decl-attr4.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/cp-tree.h trunk/gcc/cp/decl.c trunk/gcc/cp/decl2.c trunk/gcc/cp/error.c trunk/gcc/cp/parser.c trunk/gcc/cp/pt.c trunk/gcc/cp/search.c trunk/gcc/cp/semantics.c trunk/gcc/testsuite/ChangeLog \o/ You rock! Fixed in trunk (4.7) Created attachment 25746 [details]
make use of alias-declarations in libstdc++
here's the library patch to enable all the alias-declarations I'd commented out until this was ready - it builds ok, I'm testing it now
> --- Comment #14 from Benoit Jacob <jacob.benoit.1 at gmail dot com> 2011-11-07 21:57:18 UTC --- > \o/ > > You rock! Thank you, Benoit. :-) "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> a écrit: > Created attachment 25746 [details] > --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25746 > make use of alias-declarations in libstdc++ > > here's the library patch to enable all the alias-declarations I'd commented out > until this was ready - it builds ok, I'm testing it now Thanks for being so quick, Jon. Comment on attachment 25746 [details]
make use of alias-declarations in libstdc++
Thanks for implementing it! The final version I checked in was a bit different, but I'm pleased to say all the places I needed/wanted to use an alias-declaration worked fine.
|