Bug 49066 - [C++0x] Non-defining declaration of deleted function suppresses usage validation
Summary: [C++0x] Non-defining declaration of deleted function suppresses usage validation
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Jason Merrill
URL:
Keywords:
: 45539 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-05-19 15:32 UTC by Daniel Krügler
Modified: 2011-05-25 12:47 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-05-20 22:06:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Krügler 2011-05-19 15:32:03 UTC
gcc 4.7.0 20110514 (experimental) in C++0x mode compiles the following program successfully (but produces a link error):

//--
void foo() = delete;
void foo();

int main() { foo(); }
//--

It seems that the second (non-defining) declaration of the deleted function foo() has the effect of "undeleting" the initial deleted definition. I cannot deduce this kind of semantics from the FDIS wording: The program should be rejected, when compiled [In a strict sense the compiler probably behaves conforming, because in the end the program *is* ill-formed, but to me it looks like a generally expected behaviour, that this should done by the compiler, not by the linker. I'm hesitating to categorize this as an enhancement request and therefore I did not so].
Comment 1 Daniel Krügler 2011-05-19 19:06:15 UTC
I found another example that convinces me that the current behaviour is a real bug and that this issue is not just an enhancement request. Consider this example:

//---
void foo() = delete;
void foo();

template<class = decltype(foo())>
void bar(){}

int main() { bar(); }
//---

Without the second non-defining declaration of foo(), the program would be clearly rejected, but with the second declaration it is accepted. This code should be rejected independent of the existence of the second declaration of foo().
Comment 2 Jason Merrill 2011-05-21 03:57:15 UTC
Author: jason
Date: Sat May 21 03:57:12 2011
New Revision: 173993

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173993
Log:
	PR c++/49066
	* decl.c (duplicate_decls): Preserve DECL_DELETED_FN.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/defaulted26.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2011-05-21 21:35:53 UTC
Author: jason
Date: Sat May 21 21:35:50 2011
New Revision: 174003

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174003
Log:
	PR c++/49066
	* decl.c (duplicate_decls): Preserve DECL_DELETED_FN.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/defaulted26.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/decl.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 4 Jason Merrill 2011-05-25 01:14:35 UTC
Fixed for 4.6.1.
Comment 5 Jason Merrill 2011-05-25 12:47:39 UTC
*** Bug 45539 has been marked as a duplicate of this bug. ***