Bug 21682 - Disallowed using declaration
Summary: Disallowed using declaration
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P2 normal
Target Milestone: 4.9.0
Assignee: Paolo Carlini
URL:
Keywords: rejects-valid
: 26605 (view as bug list)
Depends on:
Blocks: 26605
  Show dependency treegraph
 
Reported: 2005-05-20 17:13 UTC by Dave Abrahams
Modified: 2013-09-02 09:44 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-07 04:36:05


Attachments
preprocessed source (87.70 KB, application/octet-stream)
2005-05-20 17:13 UTC, Dave Abrahams
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Abrahams 2005-05-20 17:13:04 UTC
GCC reports
  ../../../../boost/sequence/begin.hpp:53: error: 'begin' is already declared in
this scope

When creating an overload set by bringing a function into a namespace via
using-declaration.  Compile the enclosed source to demonstrate.
Comment 1 Dave Abrahams 2005-05-20 17:13:59 UTC
Created attachment 8939 [details]
preprocessed source
Comment 2 Andrew Pinski 2005-05-21 14:35:39 UTC
Confirmed, reduced testcase (which shows the problem):
template <class T>
struct t
{
  typedef typename T::type type;
};
template<> class t<int>{};

template <class T> struct t1{ };
template<> struct t1<int>
{
  typedef int type;
};

namespace name1
{
  template <class S> typename t<S>::type begin(S const& s);
  namespace name2
  {
    template <class S> typename t1<S>::type begin(S const& s);
  }
  using name2::begin;
}

/* Test calling the function. */
int f(int a) { return name1::begin(a); }

struct aa { typedef double type; };
double g(aa t) { return name1::begin(t); }
Comment 3 Paolo Carlini 2006-03-10 09:38:08 UTC
*** Bug 26605 has been marked as a duplicate of this bug. ***
Comment 4 Jason Merrill 2009-03-03 19:34:33 UTC
This is core issue 565, which has not been addressed by the committe, though John's comment makes sense to me.  How important is this issue to SFINAE techniques?
Comment 5 Dave Abrahams 2009-03-03 21:11:56 UTC
I don't know that SFINAE has anything to do with this.  Looks like I was just doing namespace composition.
Comment 6 Jason Merrill 2009-03-03 22:31:58 UTC
The names in 26605 make it clearer that it's about SFINAE, but that seems to be what your testcase is trying to do as well: if the compiler accepts the using, you would end up with an ambiguous call except that one of the templates is discarded because only one of the templates has a nested type named "type" for int or double arguments.

I don't see any reason why you would want to have multiple templates with the same parameters unless you were using SFINAE to remove all but one of them during the deduction phase of overload resolution.
Comment 7 Paolo Carlini 2013-09-01 13:42:04 UTC
Mine.
Comment 8 paolo@gcc.gnu.org 2013-09-02 09:42:42 UTC
Author: paolo
Date: Mon Sep  2 09:42:39 2013
New Revision: 202163

URL: http://gcc.gnu.org/viewcvs?rev=202163&root=gcc&view=rev
Log:
/cp
2013-09-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/21682, implement DR 565
	* name-lookup.c (compparms_for_decl_and_using_decl): New.
	(push_overloaded_decl_1, do_nonmember_using_decl): Use it.

/testsuite
2013-09-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/21682, implement DR 565
	* g++.dg/template/using24.C: New.
	* g++.dg/template/using25.C: Likewise.
	* g++.dg/template/using26.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/template/using24.C
    trunk/gcc/testsuite/g++.dg/template/using25.C
    trunk/gcc/testsuite/g++.dg/template/using26.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/name-lookup.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Paolo Carlini 2013-09-02 09:44:27 UTC
Done for 4.9.0.