public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: darrenr@optimation.com.au To: gcc-gnats@gcc.gnu.org Subject: c++/10273: g++ fails to compile sort() with a template operator that takes a pointer Date: Mon, 31 Mar 2003 10:04:00 -0000 [thread overview] Message-ID: <20030331095131.8563.qmail@sources.redhat.com> (raw) >Number: 10273 >Category: c++ >Synopsis: g++ fails to compile sort() with a template operator that takes a pointer >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Mon Mar 31 09:56:00 UTC 2003 >Closed-Date: >Last-Modified: >Originator: darrenr@optimation.com.au >Release: unknown-1.0 >Organization: >Environment: Linux linux 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386 GNU/Linux >Description: % g++ --version g++ (GCC) 3.3 20030331 (prerelease) % uname -a Linux linux 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386 GNU/Linux The following code does not compile with the above version with g++. The error message seen is as follows: % g++ foo.cpp foo.cpp: In function `void std::doit()': foo.cpp:31: error: type/value mismatch at argument 1 in template parameter list for `template<std::ClassName*<anonymous> > struct std::xLess' foo.cpp:31: error: expected a constant of type `std::ClassName*', got ` std::ClassName*' If the code is wrong then the error message is wrong. However, if I add this line: typedef ClassName * ClassNamePtr; and change all references of "ClassName *" to "ClassNamePtr", I now get an error about "x being private to ClassName (seems wrong also?) and finally making x public gets rid of all errors. This is just a code sample to show the problem, unfortunately the I'm not able to do the typedef thing in the application for other reasons :-( #include <new> #include <string> #include <vector> namespace std { class ClassName { public: ClassName(int n) { x = n; } private: int x; }; template <class ClassName *> struct xLess : binary_function<ClassName *,ClassName *,bool> { bool operator()(const ClassName *& T1, const ClassName *& T2) const { return T1->x < T2->x; } }; void doit() { vector<ClassName *> a; a.push_back(new ClassName(1)); a.push_back(new ClassName(2)); a.push_back(new ClassName(5)); sort(a.begin(), a.end(), xLess<ClassName *>()); } }; int main(int argc, char *argv[]) { std::doit(); return 0; } >How-To-Repeat: See description. >Fix: >Release-Note: >Audit-Trail: >Unformatted:
next reply other threads:[~2003-03-31 9:56 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-03-31 10:04 darrenr [this message] 2003-03-31 10:11 Gabriel Dos Reis 2003-03-31 16:10 bangerth 2003-03-31 23:26 Darren Reed (OSE) 2003-04-01 0:26 Darren Reed (OSE) 2003-04-01 2:36 Wolfgang Bangerth
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=20030331095131.8563.qmail@sources.redhat.com \ --to=darrenr@optimation.com.au \ --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).