[LLVMbugs] [Bug 20195] New: code compiles with g++-4.9.0, but not clang-3.4.2

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jul 3 00:13:33 PDT 2014


            Bug ID: 20195
           Summary: code compiles with g++-4.9.0, but not clang-3.4.2
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: janezz55 at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

clang fails to compile this code with the error:

t.cpp:24:13: error: a lambda expression may not appear inside of a constant
    address([](C* const object) noexcept {

#include <iostream>

#include <type_traits>

#include <utility>

#ifndef MEMBER
# define MEMBER(f) decltype(&f),&f
#endif // MEMBER

namespace detail

template <typename T>
auto address(T&& t) -> typename ::std::remove_reference<T>::type*
  return &t;

template <typename FP, FP fp, class C, typename ...A>
struct S
  static constexpr auto* l = false ?
    address([](C* const object) noexcept {
      return [object](A&& ...args) {
        return (object->*fp)(::std::forward<A>(args)...); 
    }) :

template <typename FP, FP fp, typename R, class C, typename ...A>
auto make_delegate(C* const object, R (C::* const)(A...)) ->
  decltype((*decltype(S<FP, fp, C, A...>::l)(nullptr))(object))
  return (*decltype(S<FP, fp, C, A...>::l)(nullptr))(object);


template <typename FP, FP fp, class C>
auto make_delegate(C* const object) ->
  decltype(detail::make_delegate<FP, fp>(object, fp))
  return detail::make_delegate<FP, fp>(object, fp);

struct A
  void operator()()
    ::std::cout << "hello world" << ::std::endl;

int main()
  A a;

  auto d(make_delegate<MEMBER(A::operator())>(&a));


  return 0;

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/20140703/d602e12c/attachment.html>

More information about the llvm-bugs mailing list