User account creation filtered due to spam.

Bug 10646 - [3.3/3.4 regression] non-const reference is incorrectly matched in a "const T" partial specialization
Summary: [3.3/3.4 regression] non-const reference is incorrectly matched in a "const T...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: 3.4.1
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 10647 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-05-06 22:46 UTC by notbob
Modified: 2004-05-05 07:11 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-07-05 23:24:13


Attachments
is_const.cpp (208 bytes, application/octet-stream)
2003-05-21 15:17 UTC, notbob
Details

Note You need to log in before you can comment on or make changes to this bug.
Description notbob 2003-05-06 22:46:00 UTC
I apologize in advance if I'm not reporting this "bug"
absolutely correctly. I haven't done this before. I
appreciate your patience. Thank you.

I believe my template should report references and functions as NOT const.

Is this "pilot error" or a compiler bug?

Release:
gcc version 3.2 20020927 (prerelease)

Environment:
in bash via cygwin on windows 98 se

How-To-Repeat:
g++ is_const.cpp
./a.exe
Comment 1 notbob 2003-05-06 22:46:00 UTC
Fix:
As a fix, you can add another specialization that matches
references and set the result to false. Alternatively,
use boost::is_const that works correctly (has workarounds).
Comment 2 Giovanni Bajo 2003-05-07 00:17:50 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: The bug for function types is confirmed in 3.2 but it's
    fixed in 3.3 (20030503) and 3.4 (20030503). It might be
    fixed in 3.2.3 as well, I don't have that version.
    
    There still is a bug with references, though:
    
    ---------------------------------
    template <typename T>
    struct is_const
    {
        typedef int type;
    };
    
    template <typename T>
    struct is_const<const T>
    {};
    
    is_const<bool&>::type a;
    ---------------------------------
    
    This should compile (but I'm not 100% sure because this
    very part of the standard is still a bit misterious for me),
    and it does on MSVC71 and Comeau/EDG, but fails with GCC
    3.3 and 3.4. Since it worked in 2.95, I rate this as a
    regression.
Comment 3 Giovanni Bajo 2003-05-07 02:23:22 UTC
From: "Giovanni Bajo" <giovannibajo@libero.it>
To: <gcc-gnats@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<notbob@tessellation.com>,
	<nobody@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>
Cc:  
Subject: Re: c++/10646: [3.3/3.4 regression] non-const reference is incorrectly matched in a "const T" partial specialization
Date: Wed, 7 May 2003 02:23:22 +0200

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10646
 
 As an additional note, the same bug exists for any combination of
 cv-qualifier. So, you can construct a template called is_volatile like the
 above to reproduce the same bug.
 
 Giovanni Bajo
Comment 4 janis187 2003-06-23 15:55:03 UTC
The regression in 10646 was introduced or exposed by this patch:

--- gcc/gcc/cp/ChangeLog ---

> 2002-02-22  Nathan Sidwell  <nathan@codesourcery.com>
>
>       PR c++/2645, DR 295
>       * cp-tree.h (tsubst_flags_t): Add tf_ignore_bad_quals,
>       tf_keep_type_decl.
>       (make_typename_type): Use tsubst_flags_t.
>       * decl.c (make_typename_type): Adjust. Return non-artificial
>       TYPE_DECLs, if required.
>       (grokdeclarator): Simplify CVR qualification handling. Allow bad
>       qualifiers on typedef types.
>       * decl2.c (handle_class_head): Adjust make_typename_type call.
>       * parse.y (nested_name_specifier): Likewise.
>       (typename_sub0): Likewise.
>       (typename_sub1): Likewise.
>       * pt.c (convert_template_argument): Adjust make_typename_type
>       return value.
>       (tsubst): Adjust cp_build_qualified_type_real calls.
>       (check_cv_quals_for_unify): Cope with alowing bad qualifications
>       on template type parms.
>       (instantiate_decl): Recheck substitutions to give warnings on bad
>       qualifications.
>       * tree.c (cp_build_qualified_type_real): Use tf_allow_bad_quals.

The regression hunt used the smaller test case from comment #2.
Comment 5 Nathan Sidwell 2003-07-13 14:10:48 UTC
Not a bug.
CV qualifiers are ignored on reference type when introduced via a typedef
or template type parameter.
Comment 6 Andrew Pinski 2004-05-05 03:52:49 UTC
Nathan, this now compiles on the mainline, this is correct right?
Comment 7 Nathan Sidwell 2004-05-05 07:11:07 UTC
yes this is now working