Bug 77795 - [6/7 Regression] ::gets declared in C++14 mode
Summary: [6/7 Regression] ::gets declared in C++14 mode
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 6.2.1
: P3 normal
Target Milestone: 6.3
Assignee: Jonathan Wakely
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-09-29 11:32 UTC by Jonathan Wakely
Modified: 2016-09-30 18:42 UTC (History)
1 user (show)

See Also:
Host:
Target: *-*-gnu-linux
Build:
Known to work: 5.4.0
Known to fail: 6.2.0, 7.0
Last reconfirmed: 2016-09-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2016-09-29 11:32:11 UTC
This is a valid C++14 program that is rejected since 6.1:

int gets;
#include <cstdio>

And this should not compile, but is accepted since 6.1:

#include <cstdio>
using ::gets;

Since we switched the default to -std=gnu++14 the configure checks for ::gets find it is missing from glibc, so we don't define _GLIBCXX_HAVE_GETS, and then in <cstdio> we do:

#ifndef _GLIBCXX_HAVE_GETS
extern "C" char* gets (char* __s) __attribute__((__deprecated__));
#endif

The configure check should use -std=gnu++98 or -std=gnu++11 (so we correctly detect the presence of ::gets when it's needed) and the declaration should only be done for C++98 and C++11 (so we only add it when it's needed).
Comment 1 Jonathan Wakely 2016-09-30 18:29:25 UTC
Author: redi
Date: Fri Sep 30 18:28:53 2016
New Revision: 240672

URL: https://gcc.gnu.org/viewcvs?rev=240672&root=gcc&view=rev
Log:
libstdc++/77795 Only declare ::gets for C++98 and C++11

	PR libstdc++/77795
	* acinclude.m4 (GLIBCXX_CHECK_STDIO_PROTO): Use -std=gnu++11 to check
	for gets.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* include/c_global/cstdio [!_GLIBCXX_HAVE_GETS] (gets): Only declare
	for C++98 and C++11.
	* include/c_std/cstdio [!_GLIBCXX_HAVE_GETS] (gets): Likewise.
	* testsuite/27_io/headers/cstdio/functions_neg.cc: New test.

Added:
    trunk/libstdc++-v3/testsuite/27_io/headers/cstdio/functions_neg.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/acinclude.m4
    trunk/libstdc++-v3/config.h.in
    trunk/libstdc++-v3/configure
    trunk/libstdc++-v3/include/c_global/cstdio
    trunk/libstdc++-v3/include/c_std/cstdio
Comment 2 Jonathan Wakely 2016-09-30 18:29:55 UTC
Author: redi
Date: Fri Sep 30 18:29:24 2016
New Revision: 240674

URL: https://gcc.gnu.org/viewcvs?rev=240674&root=gcc&view=rev
Log:
libstdc++/77795 Only declare ::gets for C++98 and C++11

	PR libstdc++/77795
	* acinclude.m4 (GLIBCXX_CHECK_STDIO_PROTO): Use -std=gnu++11 to check
	for gets.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* include/c_global/cstdio [!_GLIBCXX_HAVE_GETS] (gets): Only declare
	for C++98 and C++11.
	* include/c_std/cstdio [!_GLIBCXX_HAVE_GETS] (gets): Likewise.
	* testsuite/27_io/headers/cstdio/functions_neg.cc: New test.

Added:
    branches/gcc-6-branch/libstdc++-v3/testsuite/27_io/headers/cstdio/functions_neg.cc
Modified:
    branches/gcc-6-branch/libstdc++-v3/ChangeLog
    branches/gcc-6-branch/libstdc++-v3/acinclude.m4
    branches/gcc-6-branch/libstdc++-v3/config.h.in
    branches/gcc-6-branch/libstdc++-v3/configure
    branches/gcc-6-branch/libstdc++-v3/include/c_global/cstdio
    branches/gcc-6-branch/libstdc++-v3/include/c_std/cstdio
Comment 3 Jonathan Wakely 2016-09-30 18:42:33 UTC
Fixed for 6.3 onwards.