LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 38964 - After r336132, <string> can't be compiled by gcc in < c++11 mode
Summary: After r336132, <string> can't be compiled by gcc in < c++11 mode
Status: RESOLVED WONTFIX
Alias: None
Product: libc++
Classification: Unclassified
Component: All Bugs (show other bugs)
Version: 7.0
Hardware: PC All
: P enhancement
Assignee: Marshall Clow (home)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-16 02:29 PDT by Dimitry Andric
Modified: 2019-07-18 12:59 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric 2018-09-16 02:29:19 PDT
Because https://reviews.llvm.org/rL336132 introduces a few function templates with default template arguments, gcc cannot compile <string> anymore, when targeting c++03 or earlier:

$ echo "#include <string>" | g++ -std=c++03 -nostdinc++ -isystem /usr/include/c++/v1 -x c++ -c - -o -
In file included from <stdin>:1:
/usr/include/c++/v1/string:812:35: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
     basic_string(const _CharT* __s) {
                                   ^
/usr/include/c++/v1/string:822:62: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
         basic_string(const _CharT* __s, const _Allocator& __a);
                                                              ^
/usr/include/c++/v1/string:833:70: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
         basic_string(size_type __n, _CharT __c, const _Allocator& __a);
                                                                      ^
/usr/include/c++/v1/string:844:75: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
                               const allocator_type& __a = allocator_type());
                                                                           ^
/usr/include/c++/v1/string:848:45: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
         explicit basic_string(const _Tp& __t);
                                             ^
/usr/include/c++/v1/string:852:72: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
         explicit basic_string(const _Tp& __t, const allocator_type& __a);
                                                                        ^
/usr/include/c++/v1/string:875:43: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
     basic_string& operator=(const _Tp& __t)
                                           ^

Apparently gcc in c++03 mode does accept class templates with default arguments, but not function templates.

https://reviews.llvm.org/D48616 already stated "I may have stepped on a bug fix for old versions of gcc in C++03 mode - Eric? [ was introduced in r292830 ]", and indeed it looks like this has happened.
Comment 1 Dimitry Andric 2018-09-16 02:39:52 PDT
Btw, this was with gcc 8.2.0, but it also happens with g++ 9.0.0 20180826 (experimental), so I think it is intentional on the part of the gcc authors.
Comment 2 Marshall Clow (home) 2018-09-17 11:20:55 PDT
I tried moving the template parameters into function parameters, keeping the enable_if bits. That didn't work - introduced ambiguity.
Comment 3 Marshall Clow (home) 2018-09-18 10:00:48 PDT
Partial fix up for review at: https://reviews.llvm.org/D52240
Comment 4 Dimitry Andric 2018-10-06 07:24:50 PDT
Hm, this appears to be more difficult than I thought... :)
Comment 5 Marshall Clow (home) 2018-10-16 09:04:25 PDT
Committed revision 344616 as a partial fix.
Comment 6 Louis Dionne 2019-07-18 12:59:08 PDT
We explicitly do not support GCC in C++03 mode anymore, so I'm closing this as WONTFIX.