public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Andrea Latina <andrea.latina@to.infn.it> To: gcc-gnats@gcc.gnu.org Subject: optimization/6793: g++3.1 bug in optimization of ellipsis Date: Fri, 24 May 2002 00:56:00 -0000 [thread overview] Message-ID: <200205240757.g4O7vJx04592@to427xl.to.infn.it> (raw) >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 <iostream> #include <cstdarg> #include <cstddef> #include <cmath> template <class Type> 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<double> vector; vector = VectorNd<double>( 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:
reply other threads:[~2002-05-24 7:56 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=200205240757.g4O7vJx04592@to427xl.to.infn.it \ --to=andrea.latina@to.infn.it \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).