public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66879] New: Error message when defining a member function inside a class definition
@ 2015-07-15 14:03 anders.granlund.0 at gmail dot com
  2015-07-15 15:09 ` [Bug c++/66879] " redi at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2015-07-15 14:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

            Bug ID: 66879
           Summary: Error message when defining a member function inside a
                    class definition
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anders.granlund.0 at gmail dot com
  Target Milestone: ---

Created attachment 35988
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35988&action=edit
prog.cc used in the command line

Compile the attached program with the following command line:

gcc prog.cc

The output is the following:

prog.cc:6:22: error: definition of ‘void A::f()’ is not in namespace enclosing
‘A’ [-fpermissive]
     class A { void f() {} };
                      ^

The expected behaviour is not to get this error message. The error message seem
to suggest that the compiler thinks that the program violates [class.mfct]/2
where one sentence says:

"A member function definition that appears outside of the class definition
shall appear in a namespace scope enclosing the class definition."

Observe however that the member function definition in the given program is
made inside the class definition.

Note that if we remove the member function definition in the given program it
compiles without errors.

Output of gcc -v:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap
--enable-plugin --with-system-zlib --disable-browser-plugin
--enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
>From gcc-bugs-return-492344-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Jul 15 14:14:00 2015
Return-Path: <gcc-bugs-return-492344-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 40087 invoked by alias); 15 Jul 2015 14:13:59 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 39888 invoked by uid 55); 15 Jul 2015 14:13:56 -0000
From: "jason at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/65091] decltype(~arg) fails for template functions
Date: Wed, 15 Jul 2015 14:13:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.9.2
X-Bugzilla-Keywords: rejects-valid
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jason at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: paolo.carlini at oracle dot com
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-65091-4-xGS2dhEFPK@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-65091-4@http.gcc.gnu.org/bugzilla/>
References: <bug-65091-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-07/txt/msg01234.txt.bz2
Content-length: 507

https://gcc.gnu.org/bugzilla/show_bug.cgi?ide091

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Wed Jul 15 14:13:22 2015
New Revision: 225831

URL: https://gcc.gnu.org/viewcvs?rev"5831&root=gcc&view=rev
Log:
        PR c++/65091
        * parser.c (cp_parser_unqualified_id): Don't accept ~x in a
        template if there is no type x in scope.

Added:
    trunk/gcc/testsuite/g++.dg/parse/dtor17.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/66879] Error message when defining a member function inside a class definition
  2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
@ 2015-07-15 15:09 ` redi at gcc dot gnu.org
  2015-07-15 15:31 ` redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2015-07-15 15:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Clang compiles it OK, but EDG says:

"a.cc", line 5: error: class "A" cannot be defined in the current scope
      class A { void f() {} };

This seems similar to the G++ error, which is due to the name A referring to
::A, which should be defined in the global scope.

I'm not sure whether the definition of Y::A should be an error, or (as Clang
thinks) should declare a new type, which cannot be referred to due to the
ambiguity caused by the using-declaration.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/66879] Error message when defining a member function inside a class definition
  2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
  2015-07-15 15:09 ` [Bug c++/66879] " redi at gcc dot gnu.org
@ 2015-07-15 15:31 ` redi at gcc dot gnu.org
  2015-07-15 15:53 ` anders.granlund.0 at gmail dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2015-07-15 15:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Anders Granlund from comment #0)
> Note that if we remove the member function definition in the given program
> it compiles without errors.

I think that's the real bug. G++ should not accept this program:

class A;

namespace Y {
    using ::A;
    class A { };
}

int main()
{
  Y::A a;
  ::A* p = &a;
}

Clang rejects it because Y::A in main() is ambiguous, but EDG rejects it with
the same error as for the original testcase:

"a.cc", line 5: error: class "A" cannot be defined in the current scope
      class A { };
            ^

I believe EDG is right to reject that class-specifier because the class name A
has already been introduced into that scope, and it cannot be a definition of
::A because it doesn't use a nested-name-specifier and it isn't in the
namespace (or an enclosing namespace) of ::A.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/66879] Error message when defining a member function inside a class definition
  2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
  2015-07-15 15:09 ` [Bug c++/66879] " redi at gcc dot gnu.org
  2015-07-15 15:31 ` redi at gcc dot gnu.org
@ 2015-07-15 15:53 ` anders.granlund.0 at gmail dot com
  2015-07-15 16:06 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2015-07-15 15:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

--- Comment #3 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
Thanks for the comments! Now I remember the following bug report that I sent to
clang:

https://llvm.org/bugs/show_bug.cgi?id=24030

That bug has now been confirmed and fixed in clang, so yes this is the actual
bug and it should be fixed in gcc also.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/66879] Error message when defining a member function inside a class definition
  2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
                   ` (2 preceding siblings ...)
  2015-07-15 15:53 ` anders.granlund.0 at gmail dot com
@ 2015-07-15 16:06 ` redi at gcc dot gnu.org
  2015-07-27  0:38 ` anders.granlund.0 at gmail dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2015-07-15 16:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-07-15
            Version|unknown                     |6.0
     Ever confirmed|0                           |1

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
So confirming as accepts-invalid with this testcase:

class A;

namespace Y {
    using ::A;
    class A { };
}


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/66879] Error message when defining a member function inside a class definition
  2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
                   ` (3 preceding siblings ...)
  2015-07-15 16:06 ` redi at gcc dot gnu.org
@ 2015-07-27  0:38 ` anders.granlund.0 at gmail dot com
  2015-07-27  0:42 ` anders.granlund.0 at gmail dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2015-07-27  0:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

--- Comment #5 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
*** Bug 66888 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/66879] Error message when defining a member function inside a class definition
  2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
                   ` (4 preceding siblings ...)
  2015-07-27  0:38 ` anders.granlund.0 at gmail dot com
@ 2015-07-27  0:42 ` anders.granlund.0 at gmail dot com
  2015-07-27  0:50 ` anders.granlund.0 at gmail dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2015-07-27  0:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

--- Comment #6 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
*** Bug 66889 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/66879] Error message when defining a member function inside a class definition
  2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
                   ` (5 preceding siblings ...)
  2015-07-27  0:42 ` anders.granlund.0 at gmail dot com
@ 2015-07-27  0:50 ` anders.granlund.0 at gmail dot com
  2015-07-27  0:57 ` anders.granlund.0 at gmail dot com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2015-07-27  0:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

--- Comment #7 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
(In reply to Jonathan Wakely from comment #4)
> So confirming as accepts-invalid with this testcase:
> 
> class A;
> 
> namespace Y {
>     using ::A;
>     class A { };
> }

Here are two similar test cases pulled in from my related bug reports (i have
marked them as resolved duplicates).

The following ill-formed programs are also accepted by gcc:

  namespace R { struct f; }
  namespace S { using R::f; }
  struct S::f {};
  int main() {} 

  The above is ill-formed by [dcl.meaning]p1 (
http://eel.is/c++draft/dcl.meaning#1 )

  namespace P { struct S; }
  namespace R { using namespace P; }
  struct R::S {};
  int main() {}

  The above is also ill-formed by [dcl.meaning]p1

In general redeclarations must be done directly and not indirectly.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/66879] Error message when defining a member function inside a class definition
  2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
                   ` (6 preceding siblings ...)
  2015-07-27  0:50 ` anders.granlund.0 at gmail dot com
@ 2015-07-27  0:57 ` anders.granlund.0 at gmail dot com
  2015-07-27  1:08 ` anders.granlund.0 at gmail dot com
  2015-07-27  1:09 ` anders.granlund.0 at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2015-07-27  0:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

--- Comment #8 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
*** Bug 66901 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/66879] Error message when defining a member function inside a class definition
  2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
                   ` (7 preceding siblings ...)
  2015-07-27  0:57 ` anders.granlund.0 at gmail dot com
@ 2015-07-27  1:08 ` anders.granlund.0 at gmail dot com
  2015-07-27  1:09 ` anders.granlund.0 at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2015-07-27  1:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

--- Comment #9 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
*** Bug 66878 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/66879] Error message when defining a member function inside a class definition
  2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
                   ` (8 preceding siblings ...)
  2015-07-27  1:08 ` anders.granlund.0 at gmail dot com
@ 2015-07-27  1:09 ` anders.granlund.0 at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2015-07-27  1:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66879

--- Comment #10 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
Here comes two more test cases moved in from my related ICE on compile bug
reports:

namespace X {
    struct S;
    namespace Y {
        namespace Z = X;
        struct Z::S {};
    }
}
int main() {}

struct S;
namespace H {
    namespace P { using ::S; }
    struct P::S {};
}
int main() {}

The above programs bot gives ICE on compile (infinite recursion in
push_inner_scope_r -> stack overflow). They also involve trying to perform
redeclarations indirectly.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-07-27  1:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-15 14:03 [Bug c++/66879] New: Error message when defining a member function inside a class definition anders.granlund.0 at gmail dot com
2015-07-15 15:09 ` [Bug c++/66879] " redi at gcc dot gnu.org
2015-07-15 15:31 ` redi at gcc dot gnu.org
2015-07-15 15:53 ` anders.granlund.0 at gmail dot com
2015-07-15 16:06 ` redi at gcc dot gnu.org
2015-07-27  0:38 ` anders.granlund.0 at gmail dot com
2015-07-27  0:42 ` anders.granlund.0 at gmail dot com
2015-07-27  0:50 ` anders.granlund.0 at gmail dot com
2015-07-27  0:57 ` anders.granlund.0 at gmail dot com
2015-07-27  1:08 ` anders.granlund.0 at gmail dot com
2015-07-27  1:09 ` anders.granlund.0 at gmail dot com

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).