[LLVMbugs] [Bug 16032] New: clang -fms-extensions considers an unqualified friend decl to be a forward decl in the enclosing namespace

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu May 16 06:18:58 PDT 2013


            Bug ID: 16032
           Summary: clang -fms-extensions considers an unqualified friend
                    decl to be a forward decl in the enclosing namespace
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: reid.kleckner at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 10523
  --> http://llvm.org/bugs/attachment.cgi?id=10523&action=edit
reduced test case

$ cat menu_button.ii
namespace views {
class Widget;
namespace internal {
class RootView {
// This friend decl creates a bad forward decl of ::views::internal::Widget
  friend class Widget;
class NativeWidgetDelegate {
  virtual Widget *AsWidget() = 0;
class Widget : public internal::NativeWidgetDelegate {
  virtual Widget *AsWidget() override;

$ clang -w ./menu_button.ii -fsyntax-only
# No errors

$ clang -fms-extensions -w ./menu_button.ii -fsyntax-only
./menu_button.ii:12:19: error: return type of virtual function 'AsWidget' is
not covariant with the return type of the function it overrides
      ('views::Widget *' is not derived from 'views::internal::Widget *')
  virtual Widget *AsWidget() override;
./menu_button.ii:8:19: note: overridden virtual function is here
  virtual Widget *AsWidget() = 0;
1 error generated.

If I qualify the class name in the friend decl (::views::Widget), I can avoid
the error.  Am I required to do that?  Is the friend decl actually incorrect,
and -fms-extensions just happens to look at friend decls to find names?

The -ast-dump both with and without -fms-extensions show this node:
  `-FriendDecl 0x2b0f390 <line:7:3, col:16> 'class Widget':'class

In any case, MSVC accepts this code, so we should consider adding compatibility
for it.  I think I can fix this code easily enough by qualifying the friend
decl, so adding compatibility would be low priority for me, but would be worth

The compatibility fix would probably be a modification to the way that clang
apparently searches friend decls in -fms-extensions.  Since there is a real
forward decl in the right namespace, clang should look for that before falling
back to friend decls.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130516/02159c2d/attachment.html>

More information about the llvm-bugs mailing list