From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19176 invoked by alias); 24 May 2002 07:56:06 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 19137 invoked by uid 71); 24 May 2002 07:56:03 -0000 Resent-Date: 24 May 2002 07:56:02 -0000 Resent-Message-ID: <20020524075602.19133.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, andrea.latina@to.infn.it Received:(qmail 18039 invoked from network); 24 May 2002 07:54:06 -0000 Received: from unknown (HELO to427xl.to.infn.it) (192.84.147.73) by sources.redhat.com with SMTP; 24 May 2002 07:54:06 -0000 Received: (from latina@localhost) by to427xl.to.infn.it (8.11.6/8.11.6) id g4O7vJx04592; Fri, 24 May 2002 09:57:19 +0200 Message-Id:<200205240757.g4O7vJx04592@to427xl.to.infn.it> Date: Fri, 24 May 2002 00:56:00 -0000 From: Andrea Latina Reply-To: andrea.latina@to.infn.it To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:3.113 Subject: optimization/6793: g++3.1 bug in optimization of ellipsis X-SW-Source: 2002-05/txt/msg00760.txt.bz2 List-Id: >Number: 6793 >Category: optimization >Synopsis: varargs constructor inlined inappropriately. >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: rejects-legal >Submitter-Id: net >Arrival-Date: Fri May 24 00:56:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Andrea Latina >Release: 3.1 >Organization: >Environment: System: Linux to427xl.to.infn.it 2.4.18-4smp #1 SMP Thu May 2 18:32:34 EDT 2002 i686 unknown Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: ../gcc-3.1/configure --enable-threads >Description: In the following source I use the ellipsis to pass a variable number of arguments to the constructor of a N-dimensional vector. When I compile this source with optimization O1 or O2, I obtain an error: test.cc: In function `int main()': test.cc:24: `va_start' used in function with fixed args when I use any other optimization (or no optimization at all) it is compiled correctly. Using gcc-3.0.4 this problem doesn't appear. >How-To-Repeat: Try compiling this test with and without O2: #include #include #include #include template class VectorNd { size_t size; Type *data; public: VectorNd(const VectorNd &v ) : size(v.size) { data = new Type[size]; for (size_t i = 0; i < size; i++) data[i] = v.data[i]; } VectorNd(size_t _size, Type *_data ) : size(_size) { data = new Type[size]; for (size_t i = 0; i < size; i++) data[i] = _data[i]; } VectorNd(size_t _size, Type arg ) : size(_size) { data = new Type[size]; for (size_t i = 0; i < size; i++) data[i] = arg; } VectorNd(size_t _size = 1 ) : size(_size) { data = new Type[size]; } VectorNd(size_t _size, size_t count, ... ) : size(_size) { data = new Type[size]; va_list ap; va_start(ap, count); for (size_t i = 0; i < count; i++) data[i] = va_arg(ap, Type); va_end(ap); } ~VectorNd() { delete []data; } const VectorNd &operator = (const VectorNd &v ) { if (this != &v) { if (size != v.size) { delete []data; data = new Type[size = v.size]; } for (size_t i = 0; i < size; i++) data[i] = v.data[i]; } return *this; } friend Type abs(const VectorNd &v ) { Type sum = v.data[0] * v.data[0]; for (size_t i = 1; i < v.size; i++) sum += v.data[i] * v.data[i]; return sqrt(sum); } friend std::ostream &operator << (std::ostream &stream, const VectorNd &v ) { stream << v.data[0]; for (size_t i = 1; i < v.size; i++) stream << ", " << v.data[i]; return stream; } }; int main() { VectorNd vector; vector = VectorNd( 3, // number of components 3, // number of components passed through "..." (must be <= of the previous parameter) 1.0, 2.0, 3.0); std::cout << "abs(" << vector << ") = " << abs(vector) << std::endl; return 0; } >Fix: >Release-Note: >Audit-Trail: >Unformatted: