Bug 490211 - g++ error with -fabi-version=1
g++ error with -fabi-version=1
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: gcc (Show other bugs)
5.3
All Linux
high Severity high
: rc
: ---
Assigned To: Jakub Jelinek
BaseOS QE
:
Depends On:
Blocks: 490690
  Show dependency treegraph
 
Reported: 2009-03-13 16:30 EDT by Jeff Bastian
Modified: 2010-10-23 04:20 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 490690 (view as bug list)
Environment:
Last Closed: 2009-09-02 07:43:33 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
demo program (262 bytes, text/plain)
2009-03-13 16:31 EDT, Jeff Bastian
no flags Details
gcc41-pr27640.patch (1.86 KB, patch)
2009-03-16 10:40 EDT, Jakub Jelinek
no flags Details | Diff


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2009:1376 normal SHIPPED_LIVE gcc bug fix update 2009-09-01 07:41:20 EDT

  None (edit)
Description Jeff Bastian 2009-03-13 16:30:19 EDT
Description of problem:
g++ 4.1.x chokes on the attached code when using -fabi-version=1.  It works with abi versions 0 and 2, and g++ 3.x and 4.2 and newer work with all abi versions.

$ g++ -fabi-version=1 templtest.cc
templtest.cc: In constructor ‘S::S(U) [with U = int]’:
templtest.cc:27:   instantiated from here
templtest.cc:21: error: no matching function for call to ‘T::f(char [12])’
templtest.cc:6: note: candidates are: int T::f(char (&)[N]) const [with long unsigned int N = 12ul]


Version-Release number of selected component (if applicable):
gcc-4.1.2-44.el5.x86_64
gcc-c++-4.1.2-44.el5.x86_64

How reproducible:
every time

Steps to Reproduce:
1. g++ -fabi-version=1 templtest.cc
  
Actual results:
fails to compile and prints above errors

Expected results:
success in compiling

Additional info:
also fails on RHEL 4.7 with gcc4-c++-4.1.2-42.EL4 tech preview packages
Comment 1 Jeff Bastian 2009-03-13 16:31:05 EDT
Created attachment 335155 [details]
demo program
Comment 2 James M. Leddy 2009-03-13 16:40:34 EDT
also,

this code works when not called from a class constructor.

struct T
{
    template<size_t N>
    int f(char (&s)[N]) const
    {
        return N;
    }
};

class S
{
    char str[12];
    T t;

public:
    template<class U>
    S(U x)
    {
        printf("%dn", t.f(str));
    }
};

int main()
{
    S s(1);
    T t;

    char q[15];
    t.f(q);
}

yeilds the same error message:

templtest.cc: In constructor ‘S::S(U) [with U = int]’:
templtest.cc:27:   instantiated from here
templtest.cc:21: error: no matching function for call to ‘T::f(char [12])’
templtest.cc:6: note: candidates are: int T::f(char (&)[N]) const [with long
unsigned int N = 12ul]
Comment 3 James M. Leddy 2009-03-16 10:16:48 EDT
This shows up in the array dimension checking code:

  /* Check that the dimensions are the same.  */

  if (!cp_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)))
    return false;
  max1 = TYPE_MAX_VALUE (d1);
  max2 = TYPE_MAX_VALUE (d2);
  if (processing_template_decl && !abi_version_at_least (2)
      && !value_dependent_expression_p (max1)
      && !value_dependent_expression_p (max2))
    {
      /* With abi-1 we do not fold non-dependent array bounds, (and
	 consequently mangle them incorrectly).  We must therefore
	 fold them here, to verify the domains have the same
	 value.  */
      max1 = fold (max1);
      max2 = fold (max2);
    }

  if (!cp_tree_equal (max1, max2))
    return false;


Here cp_tree_equal fails when using -fabi-version=1 .  The comment about abi-1 is interesting, though I don't know if it has anything to do with it.

The differing values for max1 and max2 is:

(gdb) p t1.common.code
$79 = MINUS_EXPR
(gdb) p t2.common.code
$80 = INTEGER_CST
Comment 4 Jakub Jelinek 2009-03-16 10:27:25 EDT
This has been fixed by fix for http://gcc.gnu.org/PR27640 in 4.2 and above and backport of that patch fixes this on 4.1 branch as well.  Except for small comment changes the patched 4.1 instantiate_template is identical to the one in 4.4, so at least in that function no follow-ups were needed.  I haven't tried to fully bootstrap/regtest this patch yet.
Comment 5 Jakub Jelinek 2009-03-16 10:40:09 EDT
Created attachment 335355 [details]
gcc41-pr27640.patch

Backported patch.
Comment 10 James M. Leddy 2009-03-17 12:42:39 EDT
I've tested and confirmed that the patch does enable compiling w/o error with -fabi-version=1
Comment 11 Jakub Jelinek 2009-03-17 19:27:16 EDT
I've bootstrapped/regtested the patch and it caused no regressions.
Comment 19 errata-xmlrpc 2009-09-02 07:43:33 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2009-1376.html

Note You need to log in before you can comment on or make changes to this bug.