public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class
@ 2005-09-21 10:33 bdonner at physik dot tu-muenchen dot de
  2005-09-21 10:41 ` [Bug c++/23993] " bdonner at physik dot tu-muenchen dot de
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: bdonner at physik dot tu-muenchen dot de @ 2005-09-21 10:33 UTC (permalink / raw)
  To: gcc-bugs

The compiler will give the compile-time error: "invalid lvalue in unary '&'" 
 
The following code not only shows the bug, but also the non-template based  
implementation that runs and compiles perfectly. The two dimensional array is  
essential to observe the problem. The template code will run and  
compile perfectly when the 2d array is replaced by a 1d array. 
 
 
#include <iostream> 
#include <vector> 
 
/* 
const int data[2][4] = { 
    {0, 1, 2, 3}, 
    {4, 5, 6, 7} 
}; 
*/ 
 
 
// For a one dimensional array the code compiles and runs in the policy based 
// case 
const int data[4] = { 
    4, 5, 6, 7 
}; 
 
 
 
//This template implementation doesn't even compile due to some strange 
//compile-time error. 
//---------------- BEGIN TEMPLATE CODE --------------------------- 
 
template <typename T> 
class ExtremalInt { 
  private: 
    T extremal; 
 
 
  public: 
    ExtremalInt() : extremal(3) { 
    } 
 
 
    void operator()(int k) { 
      int candidate = data[k]; 
      if (extremal < candidate) { 
        extremal = candidate; 
      } 
    } 
 
 
    const int result() const { 
      return extremal; 
    } 
}; 
 
 
typedef ExtremalInt<int>  MaxExtremalInt; 
//---------------- END TEMPLATE CODE --------------------------- 
 
/* 
//---------------- BEGIN EQUIVALENT CODE --------------------------- 
class MaxExtremalInt { 
  private: 
    int extremal; 
 
 
  public: 
    MaxExtremalInt() : extremal(3) { 
    } 
 
 
    void operator()(int k) { 
      int candidate = data[1][k]; 
      if (extremal < candidate) { 
        extremal = candidate; 
      } 
    } 
 
 
    const int result() const { 
      return extremal; 
    } 
}; 
//---------------- END EQUIVALENT CODE --------------------------- 
*/ 
 
int main() { 
  int result; 
  std::vector<int> array; 
  array.push_back(1); //5 
  array.push_back(3); //7 
  array.push_back(2); //6 
  MaxExtremalInt sMax; 
  result = std::for_each(array.begin(), array.end(), sMax).result(); 
  std::cout << "Result: " << result << "\n"; 
}

-- 
           Summary: Misterious compiler error when accessing a 2d-array in a
                    template class
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bdonner at physik dot tu-muenchen dot de
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23993


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

* [Bug c++/23993] Misterious compiler error when accessing a 2d-array in a template class
  2005-09-21 10:33 [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class bdonner at physik dot tu-muenchen dot de
@ 2005-09-21 10:41 ` bdonner at physik dot tu-muenchen dot de
  2005-09-21 11:24 ` [Bug c++/23993] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bdonner at physik dot tu-muenchen dot de @ 2005-09-21 10:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bdonner at physik dot tu-muenchen dot de  2005-09-21 10:41 -------
Created an attachment (id=9786)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9786&action=view)
Code to reproduce the bug -- correct version

The inline posted version incorrectly shows the 1d instead of the 2d case.
Sorry this is my fault.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23993


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

* [Bug c++/23993] [4.0/4.1 Regression] Misterious compiler error when accessing a 2d-array in a template class
  2005-09-21 10:33 [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class bdonner at physik dot tu-muenchen dot de
  2005-09-21 10:41 ` [Bug c++/23993] " bdonner at physik dot tu-muenchen dot de
@ 2005-09-21 11:24 ` pinskia at gcc dot gnu dot org
  2005-09-21 12:19 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-21 11:24 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-21 11:24 -------
Confirmed, reduced testcase:
const int data[2][4] = {
{0, 1, 2, 3}
};
template <typename T>
void t(int k) {
  int candidate = data[1][k];
}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mmitchel at gcc dot gnu dot
                   |                            |org
           Severity|normal                      |critical
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |rejects-valid
      Known to fail|                            |4.1.0 4.0.2
      Known to work|                            |4.0.0 4.0.1
   Last reconfirmed|0000-00-00 00:00:00         |2005-09-21 11:24:24
               date|                            |
            Summary|Misterious compiler error   |[4.0/4.1 Regression]
                   |when accessing a 2d-array in|Misterious compiler error
                   |a template class            |when accessing a 2d-array in
                   |                            |a template class
   Target Milestone|---                         |4.0.2
            Version|4.0.1                       |4.0.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23993


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

* [Bug c++/23993] [4.0/4.1 Regression] Misterious compiler error when accessing a 2d-array in a template class
  2005-09-21 10:33 [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class bdonner at physik dot tu-muenchen dot de
  2005-09-21 10:41 ` [Bug c++/23993] " bdonner at physik dot tu-muenchen dot de
  2005-09-21 11:24 ` [Bug c++/23993] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
@ 2005-09-21 12:19 ` pinskia at gcc dot gnu dot org
  2005-09-21 13:10 ` mmitchel at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-21 12:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-21 12:19 -------
I forgot to mention that this worked with "4.0.2 20050826" but failed with "4.0.2 20050915".

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23993


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

* [Bug c++/23993] [4.0/4.1 Regression] Misterious compiler error when accessing a 2d-array in a template class
  2005-09-21 10:33 [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class bdonner at physik dot tu-muenchen dot de
                   ` (2 preceding siblings ...)
  2005-09-21 12:19 ` pinskia at gcc dot gnu dot org
@ 2005-09-21 13:10 ` mmitchel at gcc dot gnu dot org
  2005-09-22  0:10 ` [Bug c++/23993] [4.0/4.1 Regression] Mysterious " cvs-commit at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-09-21 13:10 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |mark at codesourcery dot com
                   |dot org                     |
             Status|NEW                         |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23993


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

* [Bug c++/23993] [4.0/4.1 Regression] Mysterious compiler error when accessing a 2d-array in a template class
  2005-09-21 10:33 [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class bdonner at physik dot tu-muenchen dot de
                   ` (3 preceding siblings ...)
  2005-09-21 13:10 ` mmitchel at gcc dot gnu dot org
@ 2005-09-22  0:10 ` cvs-commit at gcc dot gnu dot org
  2005-09-22  0:11 ` cvs-commit at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-09-22  0:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-09-22 00:09 -------
Subject: Bug 23993

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	mmitchel@gcc.gnu.org	2005-09-22 00:09:42

Modified files:
	gcc/cp         : init.c 
Added files:
	gcc/testsuite/g++.dg/template: array14.C 

Log message:
	PR c++/23993
	* init.c (integral_constant_value): Use DECL_INTEGRAL_CONSTANT_VAR_P.
	
	PR c++/23993
	* g++.dg/template/array14.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.412.2.9&r2=1.412.2.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/array14.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23993


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

* [Bug c++/23993] [4.0/4.1 Regression] Mysterious compiler error when accessing a 2d-array in a template class
  2005-09-21 10:33 [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class bdonner at physik dot tu-muenchen dot de
                   ` (5 preceding siblings ...)
  2005-09-22  0:11 ` cvs-commit at gcc dot gnu dot org
@ 2005-09-22  0:11 ` cvs-commit at gcc dot gnu dot org
  2005-09-22  0:12 ` mmitchel at gcc dot gnu dot org
  2005-10-01  1:25 ` mmitchel at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-09-22  0:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-09-22 00:11 -------
Subject: Bug 23993

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	mmitchel@gcc.gnu.org	2005-09-22 00:10:45

Modified files:
	gcc/cp         : ChangeLog 
	gcc/testsuite  : ChangeLog 

Log message:
	PR c++/23993
	* init.c (integral_constant_value): Use DECL_INTEGRAL_CONSTANT_VAR_P.
	
	PR c++/23993
	* g++.dg/template/array14.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4648.2.108&r2=1.4648.2.109
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.411&r2=1.5084.2.412



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23993


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

* [Bug c++/23993] [4.0/4.1 Regression] Mysterious compiler error when accessing a 2d-array in a template class
  2005-09-21 10:33 [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class bdonner at physik dot tu-muenchen dot de
                   ` (4 preceding siblings ...)
  2005-09-22  0:10 ` [Bug c++/23993] [4.0/4.1 Regression] Mysterious " cvs-commit at gcc dot gnu dot org
@ 2005-09-22  0:11 ` cvs-commit at gcc dot gnu dot org
  2005-09-22  0:11 ` cvs-commit at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-09-22  0:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-09-22 00:11 -------
Subject: Bug 23993

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2005-09-22 00:11:23

Modified files:
	gcc/cp         : ChangeLog init.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: array14.C 

Log message:
	PR c++/23993
	* init.c (integral_constant_value): Use DECL_INTEGRAL_CONSTANT_VAR_P.
	
	PR c++/23993
	* g++.dg/template/array14.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4899&r2=1.4900
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.429&r2=1.430
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6094&r2=1.6095
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/array14.C.diff?cvsroot=gcc&r1=1.1&r2=1.2



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23993


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

* [Bug c++/23993] [4.0/4.1 Regression] Mysterious compiler error when accessing a 2d-array in a template class
  2005-09-21 10:33 [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class bdonner at physik dot tu-muenchen dot de
                   ` (6 preceding siblings ...)
  2005-09-22  0:11 ` cvs-commit at gcc dot gnu dot org
@ 2005-09-22  0:12 ` mmitchel at gcc dot gnu dot org
  2005-10-01  1:25 ` mmitchel at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-09-22  0:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mmitchel at gcc dot gnu dot org  2005-09-22 00:12 -------
Fixed in 4.0.2.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23993


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

* [Bug c++/23993] [4.0/4.1 Regression] Mysterious compiler error when accessing a 2d-array in a template class
  2005-09-21 10:33 [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class bdonner at physik dot tu-muenchen dot de
                   ` (7 preceding siblings ...)
  2005-09-22  0:12 ` mmitchel at gcc dot gnu dot org
@ 2005-10-01  1:25 ` mmitchel at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-10-01  1:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mmitchel at gcc dot gnu dot org  2005-10-01 01:25 -------
Correcting target milestone; this will be fixed in 4.0.3.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.2                       |4.0.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23993


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

end of thread, other threads:[~2005-10-01  1:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-21 10:33 [Bug c++/23993] New: Misterious compiler error when accessing a 2d-array in a template class bdonner at physik dot tu-muenchen dot de
2005-09-21 10:41 ` [Bug c++/23993] " bdonner at physik dot tu-muenchen dot de
2005-09-21 11:24 ` [Bug c++/23993] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
2005-09-21 12:19 ` pinskia at gcc dot gnu dot org
2005-09-21 13:10 ` mmitchel at gcc dot gnu dot org
2005-09-22  0:10 ` [Bug c++/23993] [4.0/4.1 Regression] Mysterious " cvs-commit at gcc dot gnu dot org
2005-09-22  0:11 ` cvs-commit at gcc dot gnu dot org
2005-09-22  0:11 ` cvs-commit at gcc dot gnu dot org
2005-09-22  0:12 ` mmitchel at gcc dot gnu dot org
2005-10-01  1:25 ` mmitchel at gcc dot gnu dot 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).