public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109018] New: decltype of dependent expressions lookup should be done only when doing template function definition
@ 2023-03-03 22:53 nickhuang99 at hotmail dot com
2023-03-03 23:09 ` [Bug c++/109018] " pinskia at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: nickhuang99 at hotmail dot com @ 2023-03-03 22:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109018
Bug ID: 109018
Summary: decltype of dependent expressions lookup should be
done only when doing template function definition
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nickhuang99 at hotmail dot com
Target Milestone: ---
In
cppreference.com(https://en.cppreference.com/w/cpp/language/function_template#Function_template_overloading)
gives this example about dependent expression lookup issue. However, it turns
out only GCC has this parsing issue. Both clang and MSVC can solve this with no
issue.(https://www.godbolt.org/z/9anx871rr)
template<class T>
decltype(g(T())) h(); // decltype(g(T())) is a dependent type
int g(int);
template<class T>
decltype(g(T())) h()
{ // redeclaration of h() uses earlier lookup
return g(T()); // although the lookup here does find g(int)
}
int i = h<int>(); // template argument substitution fails; g(int)
// was not in scope at the first declaration of h()
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109018] decltype of dependent expressions lookup should be done only when doing template function definition
2023-03-03 22:53 [Bug c++/109018] New: decltype of dependent expressions lookup should be done only when doing template function definition nickhuang99 at hotmail dot com
@ 2023-03-03 23:09 ` pinskia at gcc dot gnu.org
2023-03-03 23:11 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-03 23:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109018
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>gives this example about dependent expression lookup issue.
Yes and it explictly it is about an invalid code example which GCC gets
correct.
The comment here:
// template argument substitution fails; g(int)
// was not in scope at the first declaration of h()
Explictly saying this code is invalid.
If you used a non-base type. ADL will find the g correctly in the substitution
of T.
E.g. this is valid:
```
struct A{};
template<class T>
decltype(g(T())) h();
int g(A);
template<class T>
decltype(g(T())) h()
return g(T());}
int i = h<A>();
```
>Both clang and MSVC can solve this with no issue.
Yes and clang and MSVC has a bug then.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109018] decltype of dependent expressions lookup should be done only when doing template function definition
2023-03-03 22:53 [Bug c++/109018] New: decltype of dependent expressions lookup should be done only when doing template function definition nickhuang99 at hotmail dot com
2023-03-03 23:09 ` [Bug c++/109018] " pinskia at gcc dot gnu.org
@ 2023-03-03 23:11 ` pinskia at gcc dot gnu.org
2023-03-03 23:13 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-03 23:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109018
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also from that page:
> If multiple declarations of the same template differ in the result of name lookup, the first such declaration is used
That is GCC gets that part correct even while clang and MSVC does not.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109018] decltype of dependent expressions lookup should be done only when doing template function definition
2023-03-03 22:53 [Bug c++/109018] New: decltype of dependent expressions lookup should be done only when doing template function definition nickhuang99 at hotmail dot com
2023-03-03 23:09 ` [Bug c++/109018] " pinskia at gcc dot gnu.org
2023-03-03 23:11 ` pinskia at gcc dot gnu.org
@ 2023-03-03 23:13 ` pinskia at gcc dot gnu.org
2023-03-04 2:08 ` nickhuang99 at hotmail dot com
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-03 23:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109018
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> template<class T>
> decltype(g(T())) h()
> return g(T());}
Typo in my example missing {
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109018] decltype of dependent expressions lookup should be done only when doing template function definition
2023-03-03 22:53 [Bug c++/109018] New: decltype of dependent expressions lookup should be done only when doing template function definition nickhuang99 at hotmail dot com
` (2 preceding siblings ...)
2023-03-03 23:13 ` pinskia at gcc dot gnu.org
@ 2023-03-04 2:08 ` nickhuang99 at hotmail dot com
2023-03-04 2:14 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: nickhuang99 at hotmail dot com @ 2023-03-04 2:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109018
qingzhe huang <nickhuang99 at hotmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|INVALID |FIXED
CC| |nickhuang99 at hotmail dot com
--- Comment #4 from qingzhe huang <nickhuang99 at hotmail dot com> ---
Thank you for your detailed explanation and really appreciate it.
My only pleading argument is that the root cause of error is from GCC cannot
find correct prototype in "template declaration" which is __NOT__ mandatory for
template definition.
For example, if I commented out the invalid template function declaration, the
parser works without issue. (https://www.godbolt.org/z/1qnTnrE1Y). So, my
argument is that GCC report error due to something which is not always
necessary. Why cannot parser postpone reporting when actually template
definition starts? Even there is not declaration, definition has all
information to work.
This will pass compilation if template declaration is commented:
// template<class T>
// decltype(g(T())) h(); // decltype(g(T())) is a dependent type
int g(int);
template<class T>
decltype(g(T())) h()
{ // redeclaration of h() uses earlier lookup
return g(T()); // although the lookup here does find g(int)
}
int i = h<int>(); // template argument substitution fails; g(int)
// was not in scope at the first declaration of h()
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109018] decltype of dependent expressions lookup should be done only when doing template function definition
2023-03-03 22:53 [Bug c++/109018] New: decltype of dependent expressions lookup should be done only when doing template function definition nickhuang99 at hotmail dot com
` (3 preceding siblings ...)
2023-03-04 2:08 ` nickhuang99 at hotmail dot com
@ 2023-03-04 2:14 ` pinskia at gcc dot gnu.org
2023-03-04 2:43 ` nickhuang99 at hotmail dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-04 2:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109018
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|FIXED |INVALID
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note g can be still found after the declaration via argument dependent lookup.
Just int is a base type so it does not have a namespace associated with it.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109018] decltype of dependent expressions lookup should be done only when doing template function definition
2023-03-03 22:53 [Bug c++/109018] New: decltype of dependent expressions lookup should be done only when doing template function definition nickhuang99 at hotmail dot com
` (4 preceding siblings ...)
2023-03-04 2:14 ` pinskia at gcc dot gnu.org
@ 2023-03-04 2:43 ` nickhuang99 at hotmail dot com
2023-03-04 12:50 ` nickhuang99 at hotmail dot com
2023-03-04 14:06 ` nickhuang99 at hotmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: nickhuang99 at hotmail dot com @ 2023-03-04 2:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109018
--- Comment #6 from qingzhe huang <nickhuang99 at hotmail dot com> ---
I agree "Note g can be still found after the declaration via argument dependent
lookup."
Can we view this issue from a different angle? The real work of parsing should
be started at "template function definition". So, if the "template function
declaration" is invalid because of "scope" of "g", then the "valid" definition
DOES NOT belong to the "invalid" declaration. i.e. There are tons of invalid
declaration are discarded as they are not required for template function
instantiation.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109018] decltype of dependent expressions lookup should be done only when doing template function definition
2023-03-03 22:53 [Bug c++/109018] New: decltype of dependent expressions lookup should be done only when doing template function definition nickhuang99 at hotmail dot com
` (5 preceding siblings ...)
2023-03-04 2:43 ` nickhuang99 at hotmail dot com
@ 2023-03-04 12:50 ` nickhuang99 at hotmail dot com
2023-03-04 14:06 ` nickhuang99 at hotmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: nickhuang99 at hotmail dot com @ 2023-03-04 12:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109018
--- Comment #7 from qingzhe huang <nickhuang99 at hotmail dot com> ---
I find another argument from decltype in cppreference
(https://en.cppreference.com/w/cpp/language/decltype#Explanation)
quote:
Because no temporary object is created, the type need not be complete or have
an available destructor, and can be abstract. This rule doesn't apply to
sub-expressions: in decltype(f(g())), g() must have a complete type, but f()
need not.
Does this mean that here "f" needs not be available when "g" is int which is
always complete? So, in our example the function "g" (aka "f" here) needs not
be available.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109018] decltype of dependent expressions lookup should be done only when doing template function definition
2023-03-03 22:53 [Bug c++/109018] New: decltype of dependent expressions lookup should be done only when doing template function definition nickhuang99 at hotmail dot com
` (6 preceding siblings ...)
2023-03-04 12:50 ` nickhuang99 at hotmail dot com
@ 2023-03-04 14:06 ` nickhuang99 at hotmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: nickhuang99 at hotmail dot com @ 2023-03-04 14:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109018
--- Comment #8 from qingzhe huang <nickhuang99 at hotmail dot com> ---
I gdb a little bit and I feel this issue is fixable. See the comparison of
"unq" and "function" below is not compatible because "function" is
"IDENTIFIER_NODE" and "unq" is "VIEW_CONVERT_EXPR". If we check and convert
"unq", we will find they are matching.
(gdb) info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000d0bafc in
tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) at
/home/nick/Downloads/gcc-dev/gcc/gcc/cp/pt.cc:20608
breakpoint already hit 1 time
(gdb) l 20608
20603 (function, args, complain, in_decl, true,
20604 integral_constant_expression_p));
20605 if (unq == error_mark_node)
20606 RETURN (error_mark_node);
20607
20608 if (unq != function)
20609 {
20610 char const *const msg
20611 = G_("%qD was not declared in this scope, "
20612 "and no declarations were found by "
(gdb) p IDENTIFIER_POINTER(function)
$16 = 0x7ffff70c42c0 "g"
(gdb) p IDENTIFIER_POINTER(DECL_NAME(TREE_OPERAND(unq,0)))
$17 = 0x7ffff70c42c0 "g"
(gdb) p TREE_CODE(function)
$18 = IDENTIFIER_NODE
(gdb) p TREE_CODE(unq)
$19 = VIEW_CONVERT_EXPR
(gdb)
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-03-04 14:06 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 22:53 [Bug c++/109018] New: decltype of dependent expressions lookup should be done only when doing template function definition nickhuang99 at hotmail dot com
2023-03-03 23:09 ` [Bug c++/109018] " pinskia at gcc dot gnu.org
2023-03-03 23:11 ` pinskia at gcc dot gnu.org
2023-03-03 23:13 ` pinskia at gcc dot gnu.org
2023-03-04 2:08 ` nickhuang99 at hotmail dot com
2023-03-04 2:14 ` pinskia at gcc dot gnu.org
2023-03-04 2:43 ` nickhuang99 at hotmail dot com
2023-03-04 12:50 ` nickhuang99 at hotmail dot com
2023-03-04 14:06 ` nickhuang99 at hotmail dot com
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).