[Bug c++/87452] decltype ignores namespace in trailing return type

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Sep 27 14:04:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87452

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-09-27
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:

extern "C" int puts(const char*);

struct vector { };

namespace N {

/**
 * Write range of random access iterators to output stream.
 */
void
operator+(const vector&)
{
  puts("pass");
}

template<typename T>
auto
f(const T& t)
-> decltype(operator+(t)) // OK
{
  return (+t);
}

template<typename T>
auto
g(const T& t)
-> decltype(+t) // fails to find operator defined in N::
{
  return (+t);
}

} // namespace N

int main()
{
  vector vec;
  N::f(vec);
  N::g(vec);
}


87452.cc: In function 'int main()':
87452.cc:38:11: error: no matching function for call to 'g(vector&)'
38 |   N::g(vec);
   |           ^
87452.cc:26:1: note: candidate: 'template<class T> decltype (+ t) N::g(const
T&)'
26 | g(const T& t)
   | ^
87452.cc:26:1: note:   template argument deduction/substitution failed:
87452.cc: In substitution of 'template<class T> decltype (+ t) N::g(const T&)
[with T = vector]':
87452.cc:38:11:   required from here
87452.cc:27:13: error: no match for 'operator+' (operand type is 'const
vector')
27 | -> decltype(+t) // fails to find operator defined in N::
   |             ^~


As the call to N::f(t) shows, the decltype in the trailing-return-type works OK
if using function call syntax (to call either a named function or the
operator-function-id). It only fails to find the overloaded operator in the
enclosing namespace for operator syntax, i.e. decltype(+t).


More information about the Gcc-bugs mailing list