clang crashes on (non-template) friend declaration.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

clang crashes on (non-template) friend declaration.

Enea Zaffanella
Hello.

The attached test shows a crash when parsing a friend declaration.
I have searched in existing bug reports concerning friendship, but I
have only found bugs related to templates (apologies if I happened to
search in the wrong places).

Stack dump:
0. Program arguments: /home/zaffanella/git-stuff/llvm/Debug/bin/clang
-cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free
-main-file-name bug.cc -mrelocation-model static -mdisable-fp-elim
-munwind-tables -target-cpu x86-64 -resource-dir
/home/zaffanella/git-stuff/llvm/Debug/lib/clang/1.1 -fmessage-length 80
-fexceptions -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics
-x c++ bug.cc
1. bug.cc:7:17: current parser token ';'
2. bug.cc:6:1: parsing struct/union/class body 'N::C'
clang: error: compiler command failed due to signal 11 (use -v to see
invocation)

NOTE: this was tested with r93873.


Having tried a few variations, I suppose that the crash is there if:
   - the class definition has a qualified name (i.e., it was forward
declared in a namespace decl and it is now defined out of that namespace);
   - the friend declaration introduces a *new* name which should be
added to the declaration context containing the class (i.e., the
namespace).


Cheers,
Enea Zaffanella.

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

bug.cc (115 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: clang crashes on (non-template) friend declaration.

John McCall

On Jan 29, 2010, at 2:21 AM, Enea Zaffanella wrote:

> Hello.
>
> The attached test shows a crash when parsing a friend declaration.
> I have searched in existing bug reports concerning friendship, but I have only found bugs related to templates (apologies if I happened to search in the wrong places).
>
> Stack dump:
> 0. Program arguments: /home/zaffanella/git-stuff/llvm/Debug/bin/clang -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -main-file-name bug.cc -mrelocation-model static -mdisable-fp-elim -munwind-tables -target-cpu x86-64 -resource-dir /home/zaffanella/git-stuff/llvm/Debug/lib/clang/1.1 -fmessage-length 80 -fexceptions -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -x c++ bug.cc
> 1. bug.cc:7:17: current parser token ';'
> 2. bug.cc:6:1: parsing struct/union/class body 'N::C'
> clang: error: compiler command failed due to signal 11 (use -v to see invocation)
>
> NOTE: this was tested with r93873.
>
>
> Having tried a few variations, I suppose that the crash is there if:
>  - the class definition has a qualified name (i.e., it was forward declared in a namespace decl and it is now defined out of that namespace);
>  - the friend declaration introduces a *new* name which should be added to the declaration context containing the class (i.e., the namespace).

Sounds like a new bug.  Please go ahead and file this, and I'll get to it soon, probably within the next week or so.  Thanks!

John.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang crashes on (non-template) friend declaration.

Enea Zaffanella
John McCall wrote:
[...]
> Sounds like a new bug.  Please go ahead and file this, and I'll get
> to it soon, probably within the next week or so.  Thanks!
>
> John.
>

We have found other errors related to non-template friend declarations.

====================
struct F {};

struct S {
   friend F::F();
   friend F::~F();
};
====================

$ llvm/Debug/bin/clang++ -fsyntax-only bug.cc
bug.cc:4:15: error: expected member name or ';' after declaration specifiers
   friend F::F();
   ~~~~~~~~~~~ ^
bug.cc:5:13: error: definition of implicitly declared destructor
   friend F::~F();
             ^
bug.cc:1:8: note: previous implicit declaration is here
struct F {};
        ^
3 diagnostics generated.

=====================

In the first case, it looks as if the constructor name is misinterpreted
to be part of the name qualifiers (maybe due to class name injection?).
The buggy error diagnostic is still there if the constructor is declared
explicitly or if a different constructor is used.

In the second case, the friend declaration is misinterpreted as if it
was defining the implicit constructor. The same buggy error diagnostic
is obtained if the implicit copy assignment operator is declared friend.

Should we add this example to the bug report just created?

Cheers,
Enea Zaffanella.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang crashes on (non-template) friend declaration.

John McCall

On Jan 30, 2010, at 1:14 AM, Enea Zaffanella wrote:

> John McCall wrote:
> [...]
>> Sounds like a new bug.  Please go ahead and file this, and I'll get
>> to it soon, probably within the next week or so.  Thanks!
>> John.
>
> We have found other errors related to non-template friend declarations.
>
> ====================
> struct F {};
>
> struct S {
>  friend F::F();
>  friend F::~F();
> };
> ====================
>
> $ llvm/Debug/bin/clang++ -fsyntax-only bug.cc
> bug.cc:4:15: error: expected member name or ';' after declaration specifiers
>  friend F::F();
>  ~~~~~~~~~~~ ^
> bug.cc:5:13: error: definition of implicitly declared destructor
>  friend F::~F();
>            ^
> bug.cc:1:8: note: previous implicit declaration is here
> struct F {};
>       ^
> 3 diagnostics generated.
>
> =====================
>
> In the first case, it looks as if the constructor name is misinterpreted to be part of the name qualifiers (maybe due to class name injection?).
> The buggy error diagnostic is still there if the constructor is declared explicitly or if a different constructor is used.
>
> In the second case, the friend declaration is misinterpreted as if it was defining the implicit constructor. The same buggy error diagnostic is obtained if the implicit copy assignment operator is declared friend.
>
> Should we add this example to the bug report just created?

These are unrelated problems and probably merit their own PR.  Thanks!

John.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev