[PATCH] handle strings as template arguments (PR 47488, 89833, 89876)

Martin Sebor msebor@gmail.com
Mon Apr 1 02:17:00 GMT 2019


To fix PR 89833, a P1 regression, the attached patch tries to
handle string literals as C++ 2a non-type template arguments
by treating them the same as brace enclosed initializer lists
(where the latter are handled correctly).  The solution makes
sure equivalent forms of array initializers such as for char[5]:

   "\0\1\2"
   "\0\1\2\0"
   { 0, 1, 2 }
   { 0, 1, 2, 0 }
   { 0, 1, 2, 0, 0 }

are treated as the same, both for overloading and mangling.
Ditto for the following equivalent forms:

   ""
   "\0"
   "\0\0\0\0"
   { }
   { 0 }
   { 0, 0, 0, 0, 0 }

and for these of struct { char a[5], b[5], c[5]; }:

   { {0,0,0,0,0}, {0,0,0,0}, {0,0,0} }
   { { 0 }, { } }
   { "" }

Since this is not handled correctly by the current code (see PR
89876 for a test case) the patch also fixes that.

I'm not at all confident the handling of classes with user-defined
constexpr ctors is 100% correct.  (I use triviality to constrain
the solution for strings but that was more of an off-the-cuff guess
than a carefully considered decision).  The g++.dg/abi/mangle71.C
test is all I've got in terms of verifying it works correctly.
I'm quite sure the C++ 2a testing could stand to be beefed up.

The patch passes x86_64-linux bootstrap and regression tests.
There are a few failures in check-c++-all tests that don't look
related to the changes (I see them with an unpatched GCC as well):

   g++.dg/spellcheck-macro-ordering-2.C
   g++.dg/cpp0x/auto52.C
   g++.dg/cpp1y/auto-neg1.C
   g++.dg/other/crash-9.C

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-89833.diff
Type: text/x-patch
Size: 31796 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190401/a9758b4a/attachment.bin>


More information about the Gcc-patches mailing list