Bug 67888 - Compiling clang 3.7.0 results in is used but never defined
Summary: Compiling clang 3.7.0 results in is used but never defined
Status: RESOLVED DUPLICATE of bug 51048
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-08 00:37 UTC by Craig Rodrigues
Modified: 2015-10-12 13:16 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 6.0
Known to fail: 4.9.4, 5.2.1
Last reconfirmed: 2015-10-08 00:00:00


Attachments
Module.ii.bz2 (165.78 KB, application/x-bzip2)
2015-10-08 00:37 UTC, Craig Rodrigues
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Craig Rodrigues 2015-10-08 00:37:19 UTC
Created attachment 36460 [details]
Module.ii.bz2

Version of GCC:

Using built-in specs.
COLLECT_GCC=/usr/local/bin/x86_64-portbld-freebsd11.0-g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-portbld-freebsd11.0/4.9.2/lto-wrapper
Target: x86_64-portbld-freebsd11.0
Configured with: ./../gcc-4.9.2/configure --target=x86_64-portbld-freebsd11.0 --disable-nls --enable-languages=c,c++ --without-headers --with-gmp=/usr/local --with-pkgversion='FreeBSD Ports Collection for amd64' --with-system-zlib --with-as=/usr/local/bin/x86_64-freebsd-as --with-ld=/usr/local/bin/x86_64-freebsd-ld --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/info/ --build=x86_64-portbld-freebsd11.0
Thread model: posix
gcc version 4.9.2 (FreeBSD Ports Collection for amd64) 


System:
FreeBSD 11.0-CURRENT #6 r286639

Problem Description:

When clang 3.7.0 is compiled with gcc 4.9.2, using this command:

/usr/local/bin/x86_64-portbld-freebsd11.0-g++ -save-temps -isystem /usr/obj/opt2/branches/head/tmp/usr/include -L/usr/obj/opt2/branches/head/tmp/usr/lib --sysroot=/usr/obj/opt2/branches/head/tmp -B/usr/local/x86_64-freebsd/bin/ -I/usr/obj/opt2/branches/head/tmp/usr/include/c++/v1 -std=gnu++11 -L/usr/obj/opt2/branches/head/tmp/../lib/libc++ --sysroot=/usr/obj/opt2/branches/head/tmp -B/usr/local/x86_64-freebsd/bin/  -O2 -pipe -I/opt2/branches/head/lib/clang/libclangbasic/../../../contrib/llvm/include -I/opt2/branches/head/lib/clang/libclangbasic/../../../contrib/llvm/tools/clang/include -I/opt2/branches/head/lib/clang/libclangbasic/../../../contrib/llvm/tools/clang/lib/Basic -I. -I/opt2/branches/head/lib/clang/libclangbasic/../../../contrib/llvm/../../lib/clang/include -DLLVM_ON_UNIX -DLLVM_ON_FREEBSD -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DCLANG_ENABLE_ARCMT -DCLANG_ENABLE_STATIC_ANALYZER -fno-strict-aliasing -DLLVM_DEFAULT_TARGET_TRIPLE=\"x86_64-unknown-freebsd11.0\" -DLLVM_HOST_TRIPLE=\"x86_64-unknown-freebsd11.0\" -DDEFAULT_SYSROOT=\"\" -fstack-protector-strong  -std=c++11 -fno-exceptions -fno-rtti  -c /opt2/branches/head/lib/clang/libclangbasic/../../../contrib/llvm/tools/clang/lib/Basic/Module.cpp -o Module.o


the following error is observed:

In file included from /opt2/branches/head/lib/clang/libclangbasic/../../../contrib/llvm/tools/clang/include/clang/Basic/SourceLocation.h:22:0,
                 from /opt2/branches/head/lib/clang/libclangbasic/../../../contrib/llvm/tools/clang/include/clang/Basic/Module.h:18,
                 from /opt2/branches/head/lib/clang/libclangbasic/../../../contrib/llvm/tools/clang/lib/Basic/Module.cpp:15:
/usr/obj/opt2/branches/head/tmp/usr/include/c++/v1/functional:1322:17: error: '_Rp std::__1::__function::__base<_Rp(_ArgTypes ...)>::operator()(_ArgTypes&& ...) [with _Rp = void; _ArgTypes = {clang::VisibleModuleSet::setVisible(clang::Module*, clang::SourceLocation, clang::VisibleModuleSet::VisibleCallback, clang::VisibleModuleSet::ConflictCallback)::Visiting}]', declared using local type 'clang::VisibleModuleSet::setVisible(clang::Module*, clang::SourceLocation, clang::VisibleModuleSet::VisibleCallback, clang::VisibleModuleSet::ConflictCallback)::Visiting', is used but never defined [-fpermissive]
     virtual _Rp operator()(_ArgTypes&& ...) = 0;
Comment 1 Craig Rodrigues 2015-10-08 00:40:21 UTC
I was able to work around this problem in two ways, as I mentioned
on the cfe-dev mailing list for LLVM: http://lists.llvm.org/pipermail/cfe-dev/2015-October/045336.html

(1)  Patch Module.cpp to move "struct Visitor" outside of VisibleModuleSet::setVisible()

OR

(2)  Add -fpermissive to command-line


clang can compile this with no problem, so I am filing the bug here.
Comment 2 Markus Trippelsdorf 2015-10-08 05:47:43 UTC
Why do you use LLVM's libc++? This is not supported in any way.
So please use gcc's libstdc++ instead.
Comment 3 Craig Rodrigues 2015-10-08 07:46:15 UTC
This is for cross-compiling the FreeBSD base system with GCC.
The FreeBSD base system has libc++, which was recently upgraded to clang 3.7.0.

Cross-compiling FreeBSD base system with GCC worked before,
with an older version of libc++.

Discussion on the llvm cfe-dev mailing list seems to point to this
being a bug in GCC, hence I filed this bug.
Comment 4 Jonathan Wakely 2015-10-08 10:29:42 UTC
Reduced:

namespace std {

template <class _Tp> struct  remove_reference {typedef _Tp type;};
template <class _Tp> struct  remove_reference<_Tp&> {typedef _Tp type;};
template <class _Tp> struct  remove_reference<_Tp&&> {typedef _Tp type;};

template <class _Tp>
inline
_Tp&&
forward(typename std::remove_reference<_Tp>::type& __t) throw()
{
    return static_cast<_Tp&&>(__t);
}

template <class _Tp>
inline
_Tp&&
forward(typename std::remove_reference<_Tp>::type&& __t) throw()
{
    return static_cast<_Tp&&>(__t);
}

template<class _Fp> class function;

namespace __function
{

template<class _Fp> class __base;

template<class _Rp, class ..._ArgTypes>
class __base<_Rp(_ArgTypes...)>
{
public:
    virtual _Rp operator()(_ArgTypes&& ...) = 0;
};

template<class _FD, class _Alloc, class _FB> class __func;

template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
    : public __base<_Rp(_ArgTypes...)>
{
public:
    virtual _Rp operator()(_ArgTypes&& ... __arg);
};



template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
_Rp
__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
{
    return {};
}
}

template<class _Rp, class ..._ArgTypes>
class function<_Rp(_ArgTypes...)>
{
    typedef __function::__base<_Rp(_ArgTypes...)> __base;
    __base* __f_;

public:

    template<class _Fp>
      function(_Fp);

    _Rp operator()(_ArgTypes...) const;
};


template<class _Rp, class ..._ArgTypes>
template <class _Fp>
function<_Rp(_ArgTypes...)>::function(_Fp)
    : __f_(0)
{
}


template<class _Rp, class ..._ArgTypes>
_Rp
function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
{
    return (*__f_)(std::forward<_ArgTypes>(__arg)...);
}

}

void setVisible()
{
  struct Visiting { };

  std::function<void(Visiting)> VisitModule { [&](Visiting) { } };
  VisitModule({});
}



Fails with 4.9 and 5.2:

mod.ii:34:17: error: ‘_Rp std::__function::__base<_Rp(_ArgTypes ...)>::operator()(_ArgTypes&& ...) [with _Rp = void; _ArgTypes = {setVisible()::Visiting}]’, declared using local type ‘setVisible()::Visiting’, is used but never defined [-fpermissive]
     virtual _Rp operator()(_ArgTypes&& ...) = 0;
                 ^

Compiles OK with trunk.
Comment 5 Jonathan Wakely 2015-10-08 10:30:34 UTC
I don't know what fixed it, or if it's worth backporting.
Comment 6 Dimitry Andric 2015-10-12 00:01:12 UTC
This appears to have been fixed with https://gcc.gnu.org/viewcvs?rev=224492&root=gcc&view=rev by Paolo Carlini, see also bug 51048.  It seems to look easy enough to backport to earlier branchs.  Paolo, can you please confirm?
Comment 7 Paolo Carlini 2015-10-12 08:52:02 UTC
I have no objections, the patch seems safe to backport. Jason, shall I go ahead if it regtests Ok on the branch?
Comment 8 Jason Merrill 2015-10-12 09:09:12 UTC
(In reply to Paolo Carlini from comment #7)
> I have no objections, the patch seems safe to backport. Jason, shall I go
> ahead if it regtests Ok on the branch?

Sure.
Comment 9 Paolo Carlini 2015-10-12 13:16:58 UTC
Done. I'm resolving this one as Dup of c++/51048.

*** This bug has been marked as a duplicate of bug 51048 ***