diff options
author | Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> | 2003-05-05 14:35:58 +0000 |
---|---|---|
committer | Kriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org> | 2003-05-05 14:35:58 +0000 |
commit | 16692dd506a49f4841b7534ae6f8e940a2cefe46 (patch) | |
tree | fc3f53c5cb371da8abedf8dbf6bc9aa5716b68b9 | |
parent | 2c9d95efce554b186e0bca82125a447b83f17ae1 (diff) | |
download | gcc-16692dd506a49f4841b7534ae6f8e940a2cefe46.zip gcc-16692dd506a49f4841b7534ae6f8e940a2cefe46.tar.gz gcc-16692dd506a49f4841b7534ae6f8e940a2cefe46.tar.bz2 |
re PR c++/10496 ([diagnostic] erroneus suggestion in diagnostic asks the user to write "&const class::memfun" which is illegal)
PR c++/10496
* typeck.c (build_unary_op): Don't output const qualifier when
output invalid pointer-to-member diagnostics.
* g++.dg/warn/pmf1.C: New test.
From-SVN: r66481
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/pmf1.C | 18 |
4 files changed, 40 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f557fe2..3567da7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 2003-05-05 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> + PR c++/10496 + * typeck.c (build_unary_op): Don't output const qualifier when + output invalid pointer-to-member diagnostics. + +2003-05-05 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> + * decl.c: Fix typos. 2003-05-05 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index bb99adc..35073dc 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4435,12 +4435,21 @@ build_unary_op (code, xarg, noconvert) if (! flag_ms_extensions) { + /* Inside constant member functions, the `this' pointer + contains an extra const qualifier. TYPE_MAIN_VARIANT + is used here to remove this const from the diagnostics. */ if (current_class_type && TREE_OPERAND (arg, 0) == current_class_ref) /* An expression like &memfn. */ - pedwarn ("ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say `&%T::%D'", base, name); + pedwarn ("ISO C++ forbids taking the address of an unqualified" + " or parenthesized non-static member function to form" + " a pointer to member function. Say `&%T::%D'", + TYPE_MAIN_VARIANT (base), name); else - pedwarn ("ISO C++ forbids taking the address of a bound member function to form a pointer to member function. Say `&%T::%D'", base, name); + pedwarn ("ISO C++ forbids taking the address of a bound member" + " function to form a pointer to member function." + " Say `&%T::%D'", + TYPE_MAIN_VARIANT (base), name); } arg = build_offset_ref (base, name); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index aec7272..c86b921 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2003-05-05 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> + PR c++/10496 + * g++.dg/warn/pmf1.C: New test. + +2003-05-05 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> + PR c++/4494 * g++.dg/warn/main.C: New test. diff --git a/gcc/testsuite/g++.dg/warn/pmf1.C b/gcc/testsuite/g++.dg/warn/pmf1.C new file mode 100644 index 0000000..013c21b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pmf1.C @@ -0,0 +1,18 @@ +// { dg-do compile } + +// Origin: benko@sztaki.hu + +// PR c++/10496: Incorrect pointer to member function diagnostics +// for constant member functions. + +struct a +{ + int f() const; +}; + + +int +a::f() const +{ + int (a::* b)() const = &f; // { dg-error "&a::f" } +} |