public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/23789] New: compilation error when template parameters have certain complexity
@ 2005-09-09 2:25 andres_takach at mentor dot com
2005-09-09 2:27 ` [Bug c++/23789] " pinskia at gcc dot gnu dot org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: andres_takach at mentor dot com @ 2005-09-09 2:25 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2656 bytes --]
While 3.4 made substantial improvements on handling of template parameters,
there are still some incorrect compiler errors that are triggered with a
combination of complexity in the template arguments and levels of templates.
In the testcase below, gcc will error out with:
t.cxx: In function void foo_function(ch_t, ch_t, ch_t*):
t.cxx:20: error: (((int)false) + 7) is not a valid template argument for
type int because it is a non-constant expression
t.cxx:20: error: no match for operator+ in A + B
The error goes away if the function foo_function (that calls the
my_int::operator +) is un-templatized. Note that the template parameter for
foo_function is not even used anywhere in the function so it should have no
impact. Simplifying the expression for the template parameters on the return
type of my_int::operator + also makes the error go away.
#define MAX(a,b) ((a) > (b) ? (a) : (b))
template<int W, bool S>
class mc_int {
public:
int d;
mc_int() { d = 0; }
mc_int(int x) { d = x; }
mc_int(const mc_int &x) { d = x.d; }
template<int W2, bool S2>
mc_int<MAX(W+(S2&&!S),W2+(S&&!S2))+1, (S||S2)> operator +(const mc_int<W2,S2>
& x) const {
return 0;
}
};
typedef mc_int<6,false> ch_t;
template <int footemplate>
void foo_function(ch_t A, ch_t B, ch_t *C) {
A + B;
}
int main() {
ch_t fooA, fooB, fooC, fooD, fooE;
fooA= (ch_t) 5;
fooB= (ch_t) 15;
ch_t CC;
foo_function<0>(fooA, fooB, &CC);
}
--
Summary: compilation error when template parameters have certain
complexity
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: andres_takach at mentor dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: gcc version 4.0.1
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23789
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/23789] compilation error when template parameters have certain complexity
2005-09-09 2:25 [Bug c++/23789] New: compilation error when template parameters have certain complexity andres_takach at mentor dot com
@ 2005-09-09 2:27 ` pinskia at gcc dot gnu dot org
2005-09-09 2:30 ` [Bug c++/23789] [3.4/4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-09 2:27 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Version|unknown |4.0.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23789
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/23789] [3.4/4.0/4.1 Regression] compilation error when template parameters have certain complexity
2005-09-09 2:25 [Bug c++/23789] New: compilation error when template parameters have certain complexity andres_takach at mentor dot com
2005-09-09 2:27 ` [Bug c++/23789] " pinskia at gcc dot gnu dot org
@ 2005-09-09 2:30 ` pinskia at gcc dot gnu dot org
2005-09-09 2:37 ` andres_takach at mentor dot com
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-09 2:30 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Known to fail| |3.4.0 4.0.0 4.1.0
Known to work| |3.3.3
Summary|compilation error when |[3.4/4.0/4.1 Regression]
|template parameters have |compilation error when
|certain complexity |template parameters have
| |certain complexity
Target Milestone|--- |4.0.2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23789
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/23789] [3.4/4.0/4.1 Regression] compilation error when template parameters have certain complexity
2005-09-09 2:25 [Bug c++/23789] New: compilation error when template parameters have certain complexity andres_takach at mentor dot com
2005-09-09 2:27 ` [Bug c++/23789] " pinskia at gcc dot gnu dot org
2005-09-09 2:30 ` [Bug c++/23789] [3.4/4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
@ 2005-09-09 2:37 ` andres_takach at mentor dot com
2005-09-09 2:39 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: andres_takach at mentor dot com @ 2005-09-09 2:37 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3960 bytes --]
------- Additional Comments From andres_takach at mentor dot com 2005-09-09 02:37 -------
t.ii file:
# 1 "t.cxx"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "t.cxx"
template<int W, bool S>
class mc_int {
public:
int d;
mc_int() { d = 0; }
mc_int(int x) { d = x; }
mc_int(const mc_int &x) { d = x.d; }
template<int W2, bool S2>
mc_int<((W+(S2&&!S)) > (W2+(S&&!S2)) ? (W+(S2&&!S)) : (W2+(S&&!S2)))+1,
(S||S2)> operator +(const mc_int<W2,S2> & x) const {
return 0;
}
};
typedef mc_int<6,false> ch_t;
template <int footemplate>
void foo_function(ch_t A, ch_t B, ch_t *C) {
A + B;
}
int main() {
ch_t fooA, fooB, fooC, fooD, fooE;
fooA= (ch_t) 5;
fooB= (ch_t) 15;
ch_t CC;
foo_function<0>(fooA, fooB, &CC);
}
---------------------------------------------------------------------
Output generated with "c++ -v -save-temps t.cxx":
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with:
/user/jasong/hdl/sb/sim/dcs_gcc/ixl/build/src/gcc-4.0.1/configure
--prefix=/user/jasong/hdl/sb/sim/dcs_gcc/ixl/exports/mgc_home/pkgs/dcs_gcc.ixl/gcc-4.0.1
--enable-languages=c,c++
Thread model: posix
gcc version 4.0.1 (Mentor-DCS)
/user/jasong/hdl/sb/sim/dcs_gcc/ixl/exports/mgc_home/pkgs/dcs_gcc.ixl/gcc-4.0.1/libexec/gcc/i686-pc-linux-gnu/4.0.1/cc1plus -E -quiet -v -D_GNU_SOURCE t.cxx -mtune=pentiumpro -fpch-preprocess -o t.ii
ignoring nonexistent directory
"/user/jasong/hdl/sb/sim/dcs_gcc/ixl/exports/mgc_home/pkgs/dcs_gcc.ixl/gcc-4.0.1/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/user/jasong/hdl/sb/sim/dcs_gcc/ixl/exports/mgc_home/pkgs/dcs_gcc.ixl/gcc-4.0.1/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../include/c++/4.0.1
/user/jasong/hdl/sb/sim/dcs_gcc/ixl/exports/mgc_home/pkgs/dcs_gcc.ixl/gcc-4.0.1/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../include/c++/4.0.1/i686-pc-linux-gnu
/user/jasong/hdl/sb/sim/dcs_gcc/ixl/exports/mgc_home/pkgs/dcs_gcc.ixl/gcc-4.0.1/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../include/c++/4.0.1/backward
/usr/local/include
/user/jasong/hdl/sb/sim/dcs_gcc/ixl/exports/mgc_home/pkgs/dcs_gcc.ixl/gcc-4.0.1/include
/user/jasong/hdl/sb/sim/dcs_gcc/ixl/exports/mgc_home/pkgs/dcs_gcc.ixl/gcc-4.0.1/lib/gcc/i686-pc-linux-gnu/4.0.1/include
/usr/include
End of search list.
/user/jasong/hdl/sb/sim/dcs_gcc/ixl/exports/mgc_home/pkgs/dcs_gcc.ixl/gcc-4.0.1/libexec/gcc/i686-pc-linux-gnu/4.0.1/cc1plus -fpreprocessed t.ii -quiet -dumpbase t.cxx -mtune=pentiumpro -auxbase t -version -o t.s
GNU C++ version 4.0.1 (Mentor-DCS) (i686-pc-linux-gnu)
compiled by GNU C version 3.4.3 (Mentor-DCS).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
t.cxx: In function void foo_function(ch_t, ch_t, ch_t*):
t.cxx:20: error: (((int)false) + 7) is not a valid template argument for type
int because it is a non-constant expression
t.cxx:20: error: no match for operator+ in A + B
--
What |Removed |Added
----------------------------------------------------------------------------
Known to work|3.3.3 |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23789
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/23789] [3.4/4.0/4.1 Regression] compilation error when template parameters have certain complexity
2005-09-09 2:25 [Bug c++/23789] New: compilation error when template parameters have certain complexity andres_takach at mentor dot com
` (2 preceding siblings ...)
2005-09-09 2:37 ` andres_takach at mentor dot com
@ 2005-09-09 2:39 ` pinskia at gcc dot gnu dot org
2005-09-09 14:06 ` bangerth at dealii dot org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-09 2:39 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-09-09 02:39 -------
Confirmed, reduced testcase:
#define MAX(a,b) ((a) > (b) ? (a) : (b))
template<int W, bool S>
class mc_int {
template<int W2, bool S2>
mc_int<MAX(W+(S2&&!S),W2+(S&&!S2))+1, false> operator +(const mc_int<W2,S2>& x) const;
};
typedef mc_int<6,false> ch_t;
template <int footemplate>
void foo_function(ch_t A, ch_t B, ch_t *C)
{
A + B;
}
Note changing foo_function to a non template, makes this work.
This is caused by not folding in templates.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
GCC build triplet|gcc version 4.0.1 |
GCC host triplet|i686-pc-linux-gnu |
GCC target triplet|i686-pc-linux-gnu |
Known to work| |3.3.3
Last reconfirmed|0000-00-00 00:00:00 |2005-09-09 02:39:23
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23789
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/23789] [3.4/4.0/4.1 Regression] compilation error when template parameters have certain complexity
2005-09-09 2:25 [Bug c++/23789] New: compilation error when template parameters have certain complexity andres_takach at mentor dot com
` (3 preceding siblings ...)
2005-09-09 2:39 ` pinskia at gcc dot gnu dot org
@ 2005-09-09 14:06 ` bangerth at dealii dot org
2005-09-09 16:58 ` mmitchel at gcc dot gnu dot org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: bangerth at dealii dot org @ 2005-09-09 14:06 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2005-09-09 14:06 -------
This is weird indeed. Here's the shortest I can come up with:
-------------------
template <int W> struct X {
template <int W2>
X< (W+(W&&W) > 1 ? W+(W&&W) : 1)+1>
operator + (const X<W2>&) const;
};
template <int dummy> void foo()
{
X<6> A,B;
A + B;
}
-----------------------------
The expression in the return type isn't fully folded, as Andrew noted:
g/x> /home/bangerth/bin/gcc-4.1-pre/bin/c++ -c x.cc
x.cc: In instantiation of ‘X<6>’:
x.cc:10: instantiated from here
x.cc:4: error: ‘(((int)true) + 7)’ is not a valid template argument for type
‘int’ because it is a non-constant expression
x.cc: In function ‘void foo()’:
x.cc:10: error: no match for ‘operator+‘ in ‘A + B‘
Weird enough, however, is that if I rename operator+ into a regular member
function, then things work just fine. Somebody's gotta explain this to me...
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23789
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/23789] [3.4/4.0/4.1 Regression] compilation error when template parameters have certain complexity
2005-09-09 2:25 [Bug c++/23789] New: compilation error when template parameters have certain complexity andres_takach at mentor dot com
` (4 preceding siblings ...)
2005-09-09 14:06 ` bangerth at dealii dot org
@ 2005-09-09 16:58 ` mmitchel at gcc dot gnu dot org
2005-09-12 22:38 ` cvs-commit at gcc dot gnu dot org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-09-09 16:58 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mmitchel at gcc dot gnu dot org 2005-09-09 16:58 -------
The problem here is that the NOP_EXPR case in tsubst is implemented by
build_nop, which unconditionally adds a NOP_EXPR. We need to simplify the
NOP_EXPR away so that fold can do its job. Perhaps we should have a CAST_EXPR
here, rather than a NOP_EXPR. I'll work it out.
--
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=23789
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/23789] [3.4/4.0/4.1 Regression] compilation error when template parameters have certain complexity
2005-09-09 2:25 [Bug c++/23789] New: compilation error when template parameters have certain complexity andres_takach at mentor dot com
` (5 preceding siblings ...)
2005-09-09 16:58 ` mmitchel at gcc dot gnu dot org
@ 2005-09-12 22:38 ` cvs-commit at gcc dot gnu dot org
2005-09-12 22:39 ` cvs-commit at gcc dot gnu dot org
2005-09-12 22:43 ` 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-12 22:38 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2005-09-12 22:38 -------
Subject: Bug 23789
CVSROOT: /cvs/gcc
Module name: gcc
Changes by: mmitchel@gcc.gnu.org 2005-09-12 22:38:34
Modified files:
gcc/cp : ChangeLog cvt.c pt.c
gcc/testsuite : ChangeLog
Added files:
gcc/testsuite/g++.dg/template: nontype14.C
Log message:
PR c++/23789
* cvt.c (perform_qualification_conversions): Don't create
unnecessary NOP_EXPRs.
* pt.c (tsubst_template_arg): Use fold_non_dependent_expr.
PR c++/23789
* g++.dg/template/nontype14.C: New test.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4885&r2=1.4886
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cvt.c.diff?cvsroot=gcc&r1=1.186&r2=1.187
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.1032&r2=1.1033
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6050&r2=1.6051
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/nontype14.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23789
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/23789] [3.4/4.0/4.1 Regression] compilation error when template parameters have certain complexity
2005-09-09 2:25 [Bug c++/23789] New: compilation error when template parameters have certain complexity andres_takach at mentor dot com
` (6 preceding siblings ...)
2005-09-12 22:38 ` cvs-commit at gcc dot gnu dot org
@ 2005-09-12 22:39 ` cvs-commit at gcc dot gnu dot org
2005-09-12 22:43 ` 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-12 22:39 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2005-09-12 22:39 -------
Subject: Bug 23789
CVSROOT: /cvs/gcc
Module name: gcc
Branch: gcc-4_0-branch
Changes by: mmitchel@gcc.gnu.org 2005-09-12 22:39:33
Modified files:
gcc/cp : ChangeLog cvt.c pt.c
gcc/testsuite : ChangeLog
Added files:
gcc/testsuite/g++.dg/template: nontype14.C
Log message:
PR c++/23789
* cvt.c (perform_qualification_conversions): Don't create
unnecessary NOP_EXPRs.
* pt.c (tsubst_template_arg): Use fold_non_dependent_expr.
PR c++/23789
* g++.dg/template/nontype14.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.99&r2=1.4648.2.100
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cvt.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.180.6.1&r2=1.180.6.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.978.2.23&r2=1.978.2.24
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.399&r2=1.5084.2.400
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/nontype14.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=23789
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/23789] [3.4/4.0/4.1 Regression] compilation error when template parameters have certain complexity
2005-09-09 2:25 [Bug c++/23789] New: compilation error when template parameters have certain complexity andres_takach at mentor dot com
` (7 preceding siblings ...)
2005-09-12 22:39 ` cvs-commit at gcc dot gnu dot org
@ 2005-09-12 22:43 ` 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-12 22:43 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mmitchel at gcc dot gnu dot org 2005-09-12 22:43 -------
Fixed in 4.0.2.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23789
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2005-09-12 22:43 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-09 2:25 [Bug c++/23789] New: compilation error when template parameters have certain complexity andres_takach at mentor dot com
2005-09-09 2:27 ` [Bug c++/23789] " pinskia at gcc dot gnu dot org
2005-09-09 2:30 ` [Bug c++/23789] [3.4/4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
2005-09-09 2:37 ` andres_takach at mentor dot com
2005-09-09 2:39 ` pinskia at gcc dot gnu dot org
2005-09-09 14:06 ` bangerth at dealii dot org
2005-09-09 16:58 ` mmitchel at gcc dot gnu dot org
2005-09-12 22:38 ` cvs-commit at gcc dot gnu dot org
2005-09-12 22:39 ` cvs-commit at gcc dot gnu dot org
2005-09-12 22:43 ` 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).