public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97174] New: out-of-namespace function definition
@ 2020-09-23 7:43 wolfgang.roehrl@gi-de.com
2020-09-23 8:04 ` [Bug c++/97174] " rguenth at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: wolfgang.roehrl@gi-de.com @ 2020-09-23 7:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97174
Bug ID: 97174
Summary: out-of-namespace function definition
Product: gcc
Version: 7.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: wolfgang.roehrl@gi-de.com
Target Milestone: ---
Hi,
I would like to post a bug report for the GNU C/C++ compiler 7.5.0.
We use the compiler to generate code for a PowerPC processor.
Invokation line for the GNU C++ compiler:
ccppc -c -x c++ --std=gnu++17 -Wall -Werror -g -mcpu=e6500 -m32
-maltivec -mvrsave -ftls-model=local-exec -msdata=sysv
-fno-common -fno-openmp -mbig -mmultiple -mno-string -misel
-mstrict-align -fverbose-asm -G 8 -O3
-I<some include paths>
-D<some #define's>
X.CPP -oX.O
// file X.CPP
#include <type_traits>
namespace N
{
template <typename T>
typename std::make_unsigned_t<T> conv (T);
}
template <typename T>
long N::conv (T val)
{ return static_cast<long>(val); }
The compiler accepts this code even though function "long N::conv (T)" is not
declared in namespace N. I think this is an illegal out-of-namespace definition
(cf. C++17 standard, 10.3.1.2/2).
With kind regards
W. Roehrl
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/97174] out-of-namespace function definition
2020-09-23 7:43 [Bug c++/97174] New: out-of-namespace function definition wolfgang.roehrl@gi-de.com
@ 2020-09-23 8:04 ` rguenth at gcc dot gnu.org
2020-09-23 8:06 ` rguenth at gcc dot gnu.org
2020-09-23 9:04 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-09-23 8:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97174
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Known to fail| |10.2.1, 7.5.0
Keywords| |accepts-invalid
Last reconfirmed| |2020-09-23
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. clang rejects it with
t.C:10:9: error: out-of-line definition of 'conv' does not match any
declaration in namespace 'N'
long N::conv (T val)
^~~~
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/97174] out-of-namespace function definition
2020-09-23 7:43 [Bug c++/97174] New: out-of-namespace function definition wolfgang.roehrl@gi-de.com
2020-09-23 8:04 ` [Bug c++/97174] " rguenth at gcc dot gnu.org
@ 2020-09-23 8:06 ` rguenth at gcc dot gnu.org
2020-09-23 9:04 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-09-23 8:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97174
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
With an instantiation added:
int main () { N::conv (1); }
we get
t.C: In function 'int main()':
t.C:13:25: error: call of overloaded 'conv(int)' is ambiguous
13 | int main () { N::conv (1); }
| ^
t.C:6:36: note: candidate: 'std::make_unsigned_t<T> N::conv(T) [with T = int;
std::make_unsigned_t<T> = unsigned int]'
6 | typename std::make_unsigned_t<T> conv (T);
| ^~~~
t.C:10:6: note: candidate: 'long int N::conv(T) [with T = int]'
10 | long N::conv (T val)
| ^
eventually no diagnostic is required for the template definition.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/97174] out-of-namespace function definition
2020-09-23 7:43 [Bug c++/97174] New: out-of-namespace function definition wolfgang.roehrl@gi-de.com
2020-09-23 8:04 ` [Bug c++/97174] " rguenth at gcc dot gnu.org
2020-09-23 8:06 ` rguenth at gcc dot gnu.org
@ 2020-09-23 9:04 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-09-23 9:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97174
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Right, the redefinition is dependent and we don't check it until instantiation.
That's allowed by the standard.
Reduced:
template<typename T> struct make_dependent { using type = T; };
template<typename T> using make_dependent_t = typename make_dependent<T>::type;
namespace N {
template <typename T>
make_dependent_t<T> conv (T);
}
template <typename T>
long N::conv (T val)
{ return static_cast<long>(val); }
Or simply:
template<typename T> struct make_dependent { using type = T; };
template<typename T> using make_dependent_t = typename make_dependent<T>::type;
template <typename T>
make_dependent_t<T> conv (T);
template <typename T>
long ::conv (T val)
{ return static_cast<long>(val); }
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-23 9:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23 7:43 [Bug c++/97174] New: out-of-namespace function definition wolfgang.roehrl@gi-de.com
2020-09-23 8:04 ` [Bug c++/97174] " rguenth at gcc dot gnu.org
2020-09-23 8:06 ` rguenth at gcc dot gnu.org
2020-09-23 9:04 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).