[llvm-bugs] [Bug 44438] New: Some symbols are not built / undefined when used in decltype

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 2 04:32:35 PST 2020


            Bug ID: 44438
           Summary: Some symbols are not built / undefined when used in
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: julien at vivenot.fr
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk


Actual results:

The following reduced test case fails to build A<C1>::foo. 
It results in a failed link :
  $ clang++ test.cpp
  /apps/dist/el6_gcc-9.2.0-64/bin/ld: /tmp/test-172f58.o:
(.rodata._ZTV1AI2C1E[_ZTV1AI2C1E]+0x10): undefined reference to `A<C1>::foo()'
  clang-9: error: linker command failed with exit code 1 (use -v to see

Expected results:

Executable should build and link just fine, including this A<C1>::foo symbol
which is used here.

Build date and results :

I personally tested on :
clang version 9.0.1 (https://github.com/llvm/llvm-project.git
Target: x86_64-unknown-linux-gnu
But I get similar results (missing A<C1>::foo) on godbolt for all versions
between 6.0.0 and trunk.

Additional information:

- Adding trailing return type information on 'Dispatcher::operator' return type
fixes the issue. Although it just repeats whats stated on the only return
- Replacing 'dispatch' trailing return type with the actual type fixes the

Test case:

#include <type_traits>

struct C1{};
struct C2{};
struct C3{};

struct IFace
  virtual void foo() = 0;

template <class T>
struct A : IFace
  void foo() override {};

template <template<typename> class F, typename Closure>
constexpr auto dispatch(int major, Closure fn)
// (*) the following does not build A<C1>::foo
  -> decltype(F<C1>{}(fn))
// (*) the following links (and builds A<C1>::foo)
//-> IFace*
  if (major == 1) return F<C1>{}(fn);
  if (major == 2) return F<C2>{}(fn);
  if (major == 3) return F<C3>{}(fn);
  return decltype(F<C1>{}(fn)){};

template <class Cn>
struct Dispatcher
  template<typename Closure>
  constexpr decltype(auto) operator()(Closure fn)
  // (*) adding the following also builds A<C1>::foo
  //  -> decltype(fn(Cn{}))
    return fn(Cn{});

int main()
  int i = 1;
  auto f = [](auto t) -> IFace*
        return new A<decltype(t)>;
  auto a = dispatch<Dispatcher>(i, f);
  return 1;

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/20200102/3a600e7c/attachment.html>

More information about the llvm-bugs mailing list