public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped
@ 2021-08-04 21:11 nickhuang99 at hotmail dot com
  2021-08-06  2:35 ` [Bug c++/101783] " nickhuang99 at hotmail dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-08-04 21:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101783
           Summary: unnecessary error when top level cv qualifier is
                    dropped
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nickhuang99 at hotmail dot com
  Target Milestone: ---

Created attachment 51261
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51261&action=edit
When no template specialization is at present, static_assert shows correct
function signature. It would impress user this error unnecessary.

The following code:

template<class T> struct A{
        typedef T& Type; // #0
};
template<class T> void f(const typename A<T>::Type){}  // #1
template <> void f<int>(const typename A<int>::Type){} // #2

will generate error:

error: ‘const’ qualifiers cannot be applied to ‘A<int>::Type’ {aka ‘int&’}

1. This error is unnecessary because the *const* as top level cv qualifier will
be dropped anyway. Considering following correct static assert even without
template specialization of #2 at presence:

static_assert(std::is_same<decltype(f<int>),void(int&)>::value);

The signature of *f<int>* would drop unnecessary const anyway as top-level cv
qualifier according to spec. So, there is no need to generate error.

2. clang gives a warning but still accept it of which I believe appropriate
(https://www.godbolt.org/z/9qWrj5asq). MSVC accept without complaining
(https://www.godbolt.org/z/3coqMnjjq).

3. I have a simple fix for this. By using *tf_keep_type_decl*, it will suppress
this unnecessary error emit and let returning result being validated anyway. In
other words, suppressing this early error doesn't break anything.

--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -4104,7 +4104,7 @@ cp_parser_make_typename_type (cp_parser *parser, tree id,
   if (identifier_p (id))
     {
       result = make_typename_type (parser->scope, id, typename_type,
-                                  /*complain=*/tf_none);
+                                  /*complain=*/tf_keep_type_decl);
       if (result == error_mark_node)
        cp_parser_diagnose_invalid_type_name (parser, id, id_location);
       return result;

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
@ 2021-08-06  2:35 ` nickhuang99 at hotmail dot com
  2021-08-06  8:38 ` redi at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-08-06  2:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from nick huang <nickhuang99 at hotmail dot com> ---
The following snippet of code and error gives more clear the issue.
Considering:

template<class T> struct A{
        typedef T& Type;
};
template<class T>
void f(const typename A<T>::Type){}
struct B{};
template <>
void f<B>(const typename A<B>::Type){}

generates following error:

 error: ‘const’ qualifiers cannot be applied to ‘A<B>::Type {aka B&}’
 void f<B>(const typename A<B>::Type){}
                                ^~~~

This would obviously confuses users about why *const* cannot be applied. Being
unable to apply the *const* to *B&* SHOULD NOT be an error, instead it is
merely a warning to be issued.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
  2021-08-06  2:35 ` [Bug c++/101783] " nickhuang99 at hotmail dot com
@ 2021-08-06  8:38 ` redi at gcc dot gnu.org
  2021-08-06  8:42 ` redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-06  8:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|diagnostic                  |
   Last reconfirmed|                            |2021-08-06
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Confirmed, doesn't seem to be a regression.

It compiles if you remove the typename:

template<class T> struct A{
        typedef T& Type;
};
template<class T>
void f(const typename A<T>::Type){}
struct B{};
template <>
void f<B>(const A<B>::Type){}

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
  2021-08-06  2:35 ` [Bug c++/101783] " nickhuang99 at hotmail dot com
  2021-08-06  8:38 ` redi at gcc dot gnu.org
@ 2021-08-06  8:42 ` redi at gcc dot gnu.org
  2021-08-06  9:15 ` redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-06  8:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
GCC 4.4 and earlier didn't accept it with the typename there:

101783.C:8: error: using 'typename' outside of template
101783.C:8: error: 'const' qualifiers cannot be applied to 'B&'


The typename started to be accepted with r0-94634

    re PR c++/22154 ([DR 382] qualified names should allow typename keyword in
front of it (even in non-templates))

    2009-07-13  Andrew Pinski

            PR C++/22154
            * parser.c (cp_parser_elaborated_type_specifier): Accept typename
in
            front of qualified names.

    2009-07-13  Andrew Pinski  <andrew_pinski@playstation.sony.com>

            PR C++/22154
            * g++.old-deja/g++.pt/typename10.C: Update for DR 382, typename in
            front of qualified names are allowed.
            * g++.dg/parse/crash10.C: Likewise.
            * g++.dg/parse/error15.C: Likewise.
            * g++.dg/parse/typename9.C: Likewise.
            * g++.dg/parse/error8.C: Likewise.

    From-SVN: r149590

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
                   ` (2 preceding siblings ...)
  2021-08-06  8:42 ` redi at gcc dot gnu.org
@ 2021-08-06  9:15 ` redi at gcc dot gnu.org
  2021-08-08 22:14 ` nickhuang99 at hotmail dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-06  9:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to nick huang from comment #0)
> The signature of *f<int>* would drop unnecessary const anyway as top-level
> cv qualifier according to spec. So, there is no need to generate error.
> 
> 2. clang gives a warning but still accept it of which I believe appropriate
> (https://www.godbolt.org/z/9qWrj5asq). MSVC accept without complaining
> (https://www.godbolt.org/z/3coqMnjjq).

EDG warns too:

"101783.C", line 8: warning: type qualifiers are meaningless here
  void f<B>(const typename A<B>::Type){}
            ^

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
                   ` (3 preceding siblings ...)
  2021-08-06  9:15 ` redi at gcc dot gnu.org
@ 2021-08-08 22:14 ` nickhuang99 at hotmail dot com
  2021-08-09  9:58 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-08-08 22:14 UTC (permalink / raw)
  To: gcc-bugs

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

nick huang <nickhuang99 at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nickhuang99 at hotmail dot com

--- Comment #5 from nick huang <nickhuang99 at hotmail dot com> ---
Created attachment 51274
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51274&action=edit
suggested fix for PR101783

Here is my suggested fix for this bug. The root cause of this bug is that it
considers reference with cv qualifier as an error by generating value for
variable "bad_quals". However, this is not correct for case of typedef. Here I
quote spec:
"Cv-qualified references are ill-formed except when the cv-qualifiers
are introduced through the use of a typedef-name ([dcl.typedef],
[temp.param]) or decltype-specifier ([dcl.type.decltype]),
in which case the cv-qualifiers are ignored."

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
                   ` (4 preceding siblings ...)
  2021-08-08 22:14 ` nickhuang99 at hotmail dot com
@ 2021-08-09  9:58 ` redi at gcc dot gnu.org
  2021-08-23 13:25 ` nickhuang99 at hotmail dot com
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-09  9:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Please send patches to the mailing list for review, they are likely to get
ignored or forgotten in bugzilla.

https://gcc.gnu.org/contribute.html#patches

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
                   ` (5 preceding siblings ...)
  2021-08-09  9:58 ` redi at gcc dot gnu.org
@ 2021-08-23 13:25 ` nickhuang99 at hotmail dot com
  2021-08-23 13:37 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-08-23 13:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from qingzhe huang <nickhuang99 at hotmail dot com> ---
Jonathan,

Is it possible for you to review and commit my patch?
(https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577040.html).


Thank you!

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
                   ` (6 preceding siblings ...)
  2021-08-23 13:25 ` nickhuang99 at hotmail dot com
@ 2021-08-23 13:37 ` redi at gcc dot gnu.org
  2021-08-23 13:41 ` nickhuang99 at hotmail dot com
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-23 13:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No, I cannot approve compiler patches.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
                   ` (7 preceding siblings ...)
  2021-08-23 13:37 ` redi at gcc dot gnu.org
@ 2021-08-23 13:41 ` nickhuang99 at hotmail dot com
  2021-10-01 15:45 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-08-23 13:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from qingzhe huang <nickhuang99 at hotmail dot com> ---
OK, Thank you very much!


________________________________
From: redi at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org>
Sent: August 23, 2021 9:37 AM
To: nickhuang99@hotmail.com <nickhuang99@hotmail.com>
Subject: [Bug c++/101783] unnecessary error when top level cv qualifier is
dropped

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No, I cannot approve compiler patches.

--
You are receiving this mail because:
You reported the bug.
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
                   ` (8 preceding siblings ...)
  2021-08-23 13:41 ` nickhuang99 at hotmail dot com
@ 2021-10-01 15:45 ` cvs-commit at gcc dot gnu.org
  2022-01-28 15:50 ` ppalka at gcc dot gnu.org
  2022-02-04 14:43 ` ppalka at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-01 15:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:7c99923f8c544ec07109e8333acb2c2388c38a1b

commit r12-4051-g7c99923f8c544ec07109e8333acb2c2388c38a1b
Author: qingzhe huang <nickhuang99@hotmail.com>
Date:   Fri Oct 1 10:46:35 2021 -0400

    c++: cv-qualified ref introduced by typedef [PR101783]

    The root cause of this bug is that it considers reference with
    cv-qualifiers as an error by generating value for variable "bad_quals".
    However, this is not correct for case of typedef. Here I quote spec
    [dcl.ref]/1 :
    "Cv-qualified references are ill-formed except when the cv-qualifiers
    are introduced through the use of a typedef-name ([dcl.typedef],
    [temp.param]) or decltype-specifier ([dcl.type.decltype]),
    in which case the cv-qualifiers are ignored."

    2021-09-30  qingzhe huang  <nickhuang99@hotmail.com>

    gcc/cp/ChangeLog:
            PR c++/101783
            * tree.c (cp_build_qualified_type_real): Exclude typedef from
            error.

    gcc/testsuite/ChangeLog:
            PR c++/101783
            * g++.dg/parse/pr101783.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
                   ` (9 preceding siblings ...)
  2021-10-01 15:45 ` cvs-commit at gcc dot gnu.org
@ 2022-01-28 15:50 ` ppalka at gcc dot gnu.org
  2022-02-04 14:43 ` ppalka at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-28 15:50 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
         Resolution|---                         |FIXED
                 CC|                            |ppalka at gcc dot gnu.org
             Status|NEW                         |RESOLVED
           Assignee|unassigned at gcc dot gnu.org      |nickhuang99 at hotmail dot com

--- Comment #11 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Marking as fixed for GCC 12, thanks for working on this!

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101783] unnecessary error when top level cv qualifier is dropped
  2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
                   ` (10 preceding siblings ...)
  2022-01-28 15:50 ` ppalka at gcc dot gnu.org
@ 2022-02-04 14:43 ` ppalka at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-02-04 14:43 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rs2740 at gmail dot com

--- Comment #12 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 69778 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-02-04 14:43 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-04 21:11 [Bug c++/101783] New: unnecessary error when top level cv qualifier is dropped nickhuang99 at hotmail dot com
2021-08-06  2:35 ` [Bug c++/101783] " nickhuang99 at hotmail dot com
2021-08-06  8:38 ` redi at gcc dot gnu.org
2021-08-06  8:42 ` redi at gcc dot gnu.org
2021-08-06  9:15 ` redi at gcc dot gnu.org
2021-08-08 22:14 ` nickhuang99 at hotmail dot com
2021-08-09  9:58 ` redi at gcc dot gnu.org
2021-08-23 13:25 ` nickhuang99 at hotmail dot com
2021-08-23 13:37 ` redi at gcc dot gnu.org
2021-08-23 13:41 ` nickhuang99 at hotmail dot com
2021-10-01 15:45 ` cvs-commit at gcc dot gnu.org
2022-01-28 15:50 ` ppalka at gcc dot gnu.org
2022-02-04 14:43 ` ppalka 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).