[LLVMbugs] [Bug 16237] New: "defaulted outside the class" error when it *is* outside the class

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jun 5 20:19:30 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16237

            Bug ID: 16237
           Summary: "defaulted outside the class" error when it *is*
                    outside the class
           Product: clang
           Version: 3.2
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: temporal at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The error "explicitly-defaulted copy constructor with a non-const parameter
must be defaulted outside the class, unless a base or member requires the
parameter to be non-const" seems to fire even when the constructor *is*
defaulted outside the class, if the class happens to be a template.  GCC
accepts this code.

PS.  Out of curiosity, why does this requirement exist?  I couldn't find an
explanation online -- this seems to be a pretty obscure corner case.

$ cat bug.c++
template <typename T>
struct S {
  S() = default;
  S(S&);
};

template <typename T>
S<T>::S(S<T>&) = default;

void f() {
  S<int> s;
  S<int> s2(s);
}

$ clang++ -std=c++11 -c bug.c++
bug.c++:4:3: error: explicitly-defaulted copy constructor with a non-const
parameter must be
      defaulted outside the class, unless a base or member requires the
parameter to be non-const
  S(S&);
  ^
bug.c++:12:10: note: in instantiation of member function 'S<int>::S' requested
here
  S<int> s2(s);
         ^
1 error generated.
$ g++ -std=c++11 -c bug.c++
$ clang++ --version
Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on LLVM
3.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
$ g++ --version
g++ (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-- 
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/20130606/8a9bc6b0/attachment.html>


More information about the llvm-bugs mailing list