Patchwork [C++] Define __cplusplus == 201300L for -std=c++1y

login
register
mail settings
Submitter Paolo Carlini
Date April 24, 2013, 6:02 p.m.
Message ID <51781E19.9030802@oracle.com>
Download mbox | patch
Permalink /patch/239288/
State New
Headers show

Comments

Paolo Carlini - April 24, 2013, 6:02 p.m.
Hi again ;)

thus I'm finishing testing (past g++.dg/dg.exp) the below. I added 
proper GNUCXX1Y and CXX1Y modes and then the rest seems largely 
straightforward.

Ok if testing passes?

Thanks,
Paolo.

///////////////////////////
/libcpp
2013-04-24  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/cpplib.h (enum c_lang): Add CLK_GNUCXX1Y and CLK_CXX1Y.
	* init.c (lang_defaults): Add defaults for the latter.
	(cpp_init_builtins): Define __cplusplus as 201300L for the latter.
	* lex.c (_cpp_lex_direct): Update.

/gcc/c-family
2013-04-24  Paolo Carlini  <paolo.carlini@oracle.com>

	* c-opts.c (set_std_cxx11): Use CLK_CXX1Y and CLK_GNUCXX1Y.

/gcc/testsuite
2013-04-24  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/cpp1y/cplusplus.C: Add.
Jason Merrill - April 24, 2013, 6:20 p.m.
On 04/24/2013 02:02 PM, Paolo Carlini wrote:
> +#if __cplusplus < 201300L

Don't test for this value.  Use <= 201103L instead.

OK with that change.

Jason
Paolo Carlini - April 26, 2013, 10:32 a.m.
On 04/24/2013 08:20 PM, Jason Merrill wrote:
> On 04/24/2013 02:02 PM, Paolo Carlini wrote:
>> +#if __cplusplus < 201300L
>
> Don't test for this value.  Use <= 201103L instead.
>
> OK with that change.
Thanks Jason.

Today I'm noticing an issue with the underlying <stdio> from glibc, 
which makes our <cstdio> unusable. It does have:

#if !defined __USE_ISOC11 \
     || (defined __cplusplus && __cplusplus <= 201103L)
/* Get a newline-terminated string from stdin, removing the newline.
    DO NOT USE THIS FUNCTION!!  There is no limit on how much it will read.

    The function has been officially removed in ISO C11.  This opportunity
    is used to also remove it from the GNU feature list.  It is now only
    available when explicitly using an old ISO C, Unix, or POSIX standard.
    GCC defines _GNU_SOURCE when building C++ code and the function is still
    in C++11, so it is also available for C++.

    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
extern char *gets (char *__s) __wur __attribute_deprecated__;

I don't think the header should check __cplusplus <= 201103L like that. 
Jakub, Jason, what do you think?

Thanks,
Paolo.
Jakub Jelinek - April 26, 2013, 10:42 a.m.
On Fri, Apr 26, 2013 at 12:32:40PM +0200, Paolo Carlini wrote:
> On 04/24/2013 08:20 PM, Jason Merrill wrote:
> >On 04/24/2013 02:02 PM, Paolo Carlini wrote:
> >>+#if __cplusplus < 201300L
> >
> >Don't test for this value.  Use <= 201103L instead.
> >
> >OK with that change.
> Thanks Jason.
> 
> Today I'm noticing an issue with the underlying <stdio> from glibc,
> which makes our <cstdio> unusable. It does have:
> 
> #if !defined __USE_ISOC11 \
>     || (defined __cplusplus && __cplusplus <= 201103L)
> /* Get a newline-terminated string from stdin, removing the newline.
>    DO NOT USE THIS FUNCTION!!  There is no limit on how much it will read.
> 
>    The function has been officially removed in ISO C11.  This opportunity
>    is used to also remove it from the GNU feature list.  It is now only
>    available when explicitly using an old ISO C, Unix, or POSIX standard.
>    GCC defines _GNU_SOURCE when building C++ code and the function is still
>    in C++11, so it is also available for C++.
> 
>    This function is a possible cancellation point and therefore not
>    marked with __THROW.  */
> extern char *gets (char *__s) __wur __attribute_deprecated__;
> 
> I don't think the header should check __cplusplus <= 201103L like
> that. Jakub, Jason, what do you think?

I guess Ulrich added this with the expectation that gets will be also
removed from C++1y.  Has there been any discussions regarding that in the WG
already?

	Jakub
Paolo Carlini - April 26, 2013, 10:51 a.m.
Hi,

On 04/26/2013 12:42 PM, Jakub Jelinek wrote:
> On Fri, Apr 26, 2013 at 12:32:40PM +0200, Paolo Carlini wrote:
>> On 04/24/2013 08:20 PM, Jason Merrill wrote:
>>> On 04/24/2013 02:02 PM, Paolo Carlini wrote:
>>>> +#if __cplusplus < 201300L
>>> Don't test for this value.  Use <= 201103L instead.
>>>
>>> OK with that change.
>> Thanks Jason.
>>
>> Today I'm noticing an issue with the underlying <stdio> from glibc,
>> which makes our <cstdio> unusable. It does have:
>>
>> #if !defined __USE_ISOC11 \
>>      || (defined __cplusplus && __cplusplus <= 201103L)
>> /* Get a newline-terminated string from stdin, removing the newline.
>>     DO NOT USE THIS FUNCTION!!  There is no limit on how much it will read.
>>
>>     The function has been officially removed in ISO C11.  This opportunity
>>     is used to also remove it from the GNU feature list.  It is now only
>>     available when explicitly using an old ISO C, Unix, or POSIX standard.
>>     GCC defines _GNU_SOURCE when building C++ code and the function is still
>>     in C++11, so it is also available for C++.
>>
>>     This function is a possible cancellation point and therefore not
>>     marked with __THROW.  */
>> extern char *gets (char *__s) __wur __attribute_deprecated__;
>>
>> I don't think the header should check __cplusplus <= 201103L like
>> that. Jakub, Jason, what do you think?
> I guess Ulrich added this with the expectation that gets will be also
> removed from C++1y.  Has there been any discussions regarding that in the WG
> already?
Not to my best knowledge. I'm adding in CC Jonathan and Daniel too.

We could certainly mirror in the C++ library what glibc does, but at 
this point it seems premature to me to assume that C++1y (C++14, in 
practice) will be stricter than C++11 as regards gets.

Paolo.
Daniel Krügler - April 26, 2013, 10:57 a.m.
2013/4/26 Paolo Carlini <paolo.carlini@oracle.com>:
> Hi,
>
> On 04/26/2013 12:42 PM, Jakub Jelinek wrote:
>>
>> On Fri, Apr 26, 2013 at 12:32:40PM +0200, Paolo Carlini wrote:
>>>
>>> On 04/24/2013 08:20 PM, Jason Merrill wrote:
>>>>
>>>> On 04/24/2013 02:02 PM, Paolo Carlini wrote:
>>>>>
>>>>> +#if __cplusplus < 201300L
>>>>
>>>> Don't test for this value.  Use <= 201103L instead.
>>>>
>>>> OK with that change.
>>>
>>> Thanks Jason.
>>>
>>> Today I'm noticing an issue with the underlying <stdio> from glibc,
>>> which makes our <cstdio> unusable. It does have:
>>>
>>> #if !defined __USE_ISOC11 \
>>>      || (defined __cplusplus && __cplusplus <= 201103L)
>>> /* Get a newline-terminated string from stdin, removing the newline.
>>>     DO NOT USE THIS FUNCTION!!  There is no limit on how much it will
>>> read.
>>>
>>>     The function has been officially removed in ISO C11.  This
>>> opportunity
>>>     is used to also remove it from the GNU feature list.  It is now only
>>>     available when explicitly using an old ISO C, Unix, or POSIX
>>> standard.
>>>     GCC defines _GNU_SOURCE when building C++ code and the function is
>>> still
>>>     in C++11, so it is also available for C++.
>>>
>>>     This function is a possible cancellation point and therefore not
>>>     marked with __THROW.  */
>>> extern char *gets (char *__s) __wur __attribute_deprecated__;
>>>
>>> I don't think the header should check __cplusplus <= 201103L like
>>> that. Jakub, Jason, what do you think?
>>
>> I guess Ulrich added this with the expectation that gets will be also
>> removed from C++1y.  Has there been any discussions regarding that in the
>> WG
>> already?
>
> Not to my best knowledge. I'm adding in CC Jonathan and Daniel too.
>
> We could certainly mirror in the C++ library what glibc does, but at this
> point it seems premature to me to assume that C++1y (C++14, in practice)
> will be stricter than C++11 as regards gets.

Jonathan recently submitted an LWG issue for this (not yet part of the
available list). I'm in the process to add the new issue within the
following days. He's essentially suggesting to remove get() from
C++14.

- Daniel

> Paolo.
Daniel Krügler - April 26, 2013, 11 a.m.
2013/4/26 Daniel Krügler <daniel.kruegler@gmail.com>:
> 2013/4/26 Paolo Carlini <paolo.carlini@oracle.com>:
>> Hi,
>>
>> On 04/26/2013 12:42 PM, Jakub Jelinek wrote:
>>>
>>> On Fri, Apr 26, 2013 at 12:32:40PM +0200, Paolo Carlini wrote:
>>>>
>>>> On 04/24/2013 08:20 PM, Jason Merrill wrote:
>>>>>
>>>>> On 04/24/2013 02:02 PM, Paolo Carlini wrote:
>>>>>>
>>>>>> +#if __cplusplus < 201300L
>>>>>
>>>>> Don't test for this value.  Use <= 201103L instead.
>>>>>
>>>>> OK with that change.
>>>>
>>>> Thanks Jason.
>>>>
>>>> Today I'm noticing an issue with the underlying <stdio> from glibc,
>>>> which makes our <cstdio> unusable. It does have:
>>>>
>>>> #if !defined __USE_ISOC11 \
>>>>      || (defined __cplusplus && __cplusplus <= 201103L)
>>>> /* Get a newline-terminated string from stdin, removing the newline.
>>>>     DO NOT USE THIS FUNCTION!!  There is no limit on how much it will
>>>> read.
>>>>
>>>>     The function has been officially removed in ISO C11.  This
>>>> opportunity
>>>>     is used to also remove it from the GNU feature list.  It is now only
>>>>     available when explicitly using an old ISO C, Unix, or POSIX
>>>> standard.
>>>>     GCC defines _GNU_SOURCE when building C++ code and the function is
>>>> still
>>>>     in C++11, so it is also available for C++.
>>>>
>>>>     This function is a possible cancellation point and therefore not
>>>>     marked with __THROW.  */
>>>> extern char *gets (char *__s) __wur __attribute_deprecated__;
>>>>
>>>> I don't think the header should check __cplusplus <= 201103L like
>>>> that. Jakub, Jason, what do you think?
>>>
>>> I guess Ulrich added this with the expectation that gets will be also
>>> removed from C++1y.  Has there been any discussions regarding that in the
>>> WG
>>> already?
>>
>> Not to my best knowledge. I'm adding in CC Jonathan and Daniel too.
>>
>> We could certainly mirror in the C++ library what glibc does, but at this
>> point it seems premature to me to assume that C++1y (C++14, in practice)
>> will be stricter than C++11 as regards gets.
>
> Jonathan recently submitted an LWG issue for this (not yet part of the
> available list). I'm in the process to add the new issue within the
> following days. He's essentially suggesting to remove get() from
> C++14.

To clarify this: The C++ Standard currently refers to a get() function
that does not exist anymore in the reference C99. So, its removal
looks more than reasonable to me.

> - Daniel
>
>> Paolo.
Daniel Krügler - April 26, 2013, 11:06 a.m.
2013/4/26 Daniel Krügler <daniel.kruegler@gmail.com>:
> 2013/4/26 Daniel Krügler <daniel.kruegler@gmail.com>:
>> 2013/4/26 Paolo Carlini <paolo.carlini@oracle.com>:
>>> Hi,
>>>
>>> On 04/26/2013 12:42 PM, Jakub Jelinek wrote:
>>>>
>>>> On Fri, Apr 26, 2013 at 12:32:40PM +0200, Paolo Carlini wrote:
>>>>>
>>>>> On 04/24/2013 08:20 PM, Jason Merrill wrote:
>>>>>>
>>>>>> On 04/24/2013 02:02 PM, Paolo Carlini wrote:
>>>>>>>
>>>>>>> +#if __cplusplus < 201300L
>>>>>>
>>>>>> Don't test for this value.  Use <= 201103L instead.
>>>>>>
>>>>>> OK with that change.
>>>>>
>>>>> Thanks Jason.
>>>>>
>>>>> Today I'm noticing an issue with the underlying <stdio> from glibc,
>>>>> which makes our <cstdio> unusable. It does have:
>>>>>
>>>>> #if !defined __USE_ISOC11 \
>>>>>      || (defined __cplusplus && __cplusplus <= 201103L)
>>>>> /* Get a newline-terminated string from stdin, removing the newline.
>>>>>     DO NOT USE THIS FUNCTION!!  There is no limit on how much it will
>>>>> read.
>>>>>
>>>>>     The function has been officially removed in ISO C11.  This
>>>>> opportunity
>>>>>     is used to also remove it from the GNU feature list.  It is now only
>>>>>     available when explicitly using an old ISO C, Unix, or POSIX
>>>>> standard.
>>>>>     GCC defines _GNU_SOURCE when building C++ code and the function is
>>>>> still
>>>>>     in C++11, so it is also available for C++.
>>>>>
>>>>>     This function is a possible cancellation point and therefore not
>>>>>     marked with __THROW.  */
>>>>> extern char *gets (char *__s) __wur __attribute_deprecated__;
>>>>>
>>>>> I don't think the header should check __cplusplus <= 201103L like
>>>>> that. Jakub, Jason, what do you think?
>>>>
>>>> I guess Ulrich added this with the expectation that gets will be also
>>>> removed from C++1y.  Has there been any discussions regarding that in the
>>>> WG
>>>> already?
>>>
>>> Not to my best knowledge. I'm adding in CC Jonathan and Daniel too.
>>>
>>> We could certainly mirror in the C++ library what glibc does, but at this
>>> point it seems premature to me to assume that C++1y (C++14, in practice)
>>> will be stricter than C++11 as regards gets.
>>
>> Jonathan recently submitted an LWG issue for this (not yet part of the
>> available list). I'm in the process to add the new issue within the
>> following days. He's essentially suggesting to remove get() from
>> C++14.
>
> To clarify this: The C++ Standard currently refers to a get() function
> that does not exist anymore in the reference C99. So, its removal
> looks more than reasonable to me.

Sorry, I need to correct me here: gets() is part of C99 TC3, but has
been deprecated.

>> - Daniel
>>
>>> Paolo.
Jonathan Wakely - April 26, 2013, 12:41 p.m.
On 26 April 2013 12:06, Daniel Krügler wrote:
>>>
>>> Jonathan recently submitted an LWG issue for this (not yet part of the
>>> available list). I'm in the process to add the new issue within the
>>> following days. He's essentially suggesting to remove get() from
>>> C++14.
>>
>> To clarify this: The C++ Standard currently refers to a get() function
>> that does not exist anymore in the reference C99. So, its removal
>> looks more than reasonable to me.
>
> Sorry, I need to correct me here: gets() is part of C99 TC3, but has
> been deprecated.

Yes. When I submitted the issue I was under the impression (along with
most of the BSI C++ panel) that the C++ standard references the
current C standard, which is now C11.  I was told in Bristol that the
reference to ISO/IEC 9899:1999 is fine and so we only reference the
C99 library, which still includes gets().  So I think the issue I
submitted is NAD.

IMHO it wouldn't be a bad thing to remove gets() from the C++ Standard
Library even if it's technically still in C99.  It is evil and should
be killed with fire.  But that probably can't be handled with a DR and
so is too late for C++14.
Daniel Krügler - April 26, 2013, 12:50 p.m.
2013/4/26 Jonathan Wakely <jwakely.gcc@gmail.com>:
> On 26 April 2013 12:06, Daniel Krügler wrote:
>>>>
>>>> Jonathan recently submitted an LWG issue for this (not yet part of the
>>>> available list). I'm in the process to add the new issue within the
>>>> following days. He's essentially suggesting to remove get() from
>>>> C++14.
>>>
>>> To clarify this: The C++ Standard currently refers to a get() function
>>> that does not exist anymore in the reference C99. So, its removal
>>> looks more than reasonable to me.
>>
>> Sorry, I need to correct me here: gets() is part of C99 TC3, but has
>> been deprecated.
>
> Yes. When I submitted the issue I was under the impression (along with
> most of the BSI C++ panel) that the C++ standard references the
> current C standard, which is now C11.  I was told in Bristol that the
> reference to ISO/IEC 9899:1999 is fine and so we only reference the
> C99 library, which still includes gets().  So I think the issue I
> submitted is NAD.
>
> IMHO it wouldn't be a bad thing to remove gets() from the C++ Standard
> Library even if it's technically still in C99.  It is evil and should
> be killed with fire.  But that probably can't be handled with a DR and
> so is too late for C++14.

There exists at least one further issue similar to that one such as

http://cplusplus.github.io/LWG/lwg-active.html#2241

so lets see (Per minimum the gets() function should still keep the
deprecated attribute).

- Daniel
Gabriel Dos Reis - April 26, 2013, 1:34 p.m.
On Fri, Apr 26, 2013 at 7:41 AM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>  But that probably can't be handled with a DR and
> so is too late for C++14.

BSI still gets to submit a NB comment demanding its removal.

-- Gaby

Patch

Index: gcc/c-family/c-opts.c
===================================================================
--- gcc/c-family/c-opts.c	(revision 198258)
+++ gcc/c-family/c-opts.c	(working copy)
@@ -1471,7 +1471,7 @@  set_std_cxx11 (int iso)
 static void
 set_std_cxx1y (int iso)
 {
-  cpp_set_lang (parse_in, iso ? CLK_CXX11: CLK_GNUCXX11);
+  cpp_set_lang (parse_in, iso ? CLK_CXX1Y: CLK_GNUCXX1Y);
   flag_no_gnu_keywords = iso;
   flag_no_nonansi_builtin = iso;
   flag_iso = iso;
Index: gcc/testsuite/g++.dg/cpp1y/cplusplus.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/cplusplus.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp1y/cplusplus.C	(working copy)
@@ -0,0 +1,5 @@ 
+// { dg-options "-std=c++1y" }
+
+#if __cplusplus < 201300L
+#error
+#endif
Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 198258)
+++ libcpp/include/cpplib.h	(working copy)
@@ -165,7 +165,8 @@  enum cpp_ttype
 /* C language kind, used when calling cpp_create_reader.  */
 enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11,
 	     CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_STDC11,
-	     CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11, CLK_ASM};
+	     CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
+	     CLK_GNUCXX1Y, CLK_CXX1Y, CLK_ASM};
 
 /* Payload of a NUMBER, STRING, CHAR or COMMENT token.  */
 struct GTY(()) cpp_string {
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 198258)
+++ libcpp/init.c	(working copy)
@@ -98,11 +98,13 @@  static const struct lang_flags lang_defaults[] =
   /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1,   0,   0,    0 },
   /* GNUCXX11 */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
   /* CXX11    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
+  /* GNUCXX1Y */  { 1,  1,  1,   0,  0,   1,   1,   1,   1,    1 },
+  /* CXX1Y    */  { 1,  1,  1,   0,  1,   1,   1,   1,   1,    1 },
   /* ASM      */  { 0,  0,  1,   0,  0,   1,   0,   0,   0,    0 }
-  /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX11, and
-     CXX11 when no longer experimental (when all uses of identifiers
-     in the compiler have been audited for correct handling of
-     extended identifiers).  */
+  /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX11, CXX11,
+     GNUCXX1Y, and CXX1Y when no longer experimental (when all uses of
+     identifiers in the compiler have been audited for correct handling
+     of extended identifiers).  */
 };
 
 /* Sets internal flags correctly for a given language.  */
@@ -476,8 +478,11 @@  cpp_init_builtins (cpp_reader *pfile, int hosted)
 
   if (CPP_OPTION (pfile, cplusplus))
     {
-      if (CPP_OPTION (pfile, lang) == CLK_CXX11
-	   || CPP_OPTION (pfile, lang) == CLK_GNUCXX11)
+      if (CPP_OPTION (pfile, lang) == CLK_CXX1Y
+	  || CPP_OPTION (pfile, lang) == CLK_GNUCXX1Y)
+	_cpp_define_builtin (pfile, "__cplusplus 201300L");
+      else if (CPP_OPTION (pfile, lang) == CLK_CXX11
+	       || CPP_OPTION (pfile, lang) == CLK_GNUCXX11)
 	_cpp_define_builtin (pfile, "__cplusplus 201103L");
       else
 	_cpp_define_builtin (pfile, "__cplusplus 199711L");
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 198258)
+++ libcpp/lex.c	(working copy)
@@ -2298,8 +2298,8 @@  _cpp_lex_direct (cpp_reader *pfile)
 		 is neither : nor >, the < is treated as a preprocessor
 		 token by itself".  */
 	      if (CPP_OPTION (pfile, cplusplus)
-		  && (CPP_OPTION (pfile, lang) == CLK_CXX11
-		      || CPP_OPTION (pfile, lang) == CLK_GNUCXX11)
+		  && CPP_OPTION (pfile, lang) != CLK_CXX98
+		  && CPP_OPTION (pfile, lang) != CLK_GNUCXX
 		  && buffer->cur[1] == ':'
 		  && buffer->cur[2] != ':' && buffer->cur[2] != '>')
 		break;