Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c++17 inline variables with clang cause a linker error in ndk 15c #538

Closed
martinbonaciugome opened this issue Oct 4, 2017 · 13 comments
Closed

Comments

@martinbonaciugome
Copy link

c++17 inline variables with clang cause a linker error in ndk 15c. They are suppose to be supported since clang 3.9, so 5.0 should definitely work.

windows 64bit, ndk 15c, cmake

@enh
Copy link
Contributor

enh commented Oct 5, 2017

example?

@martinbonaciugome
Copy link
Author

martinbonaciugome commented Oct 5, 2017

havent tried to see if a smaller project succeeds, but our current project is cross-platform with ios, and it works in xcode 8+. small enough snippet to get an idea is:

MemoryAllocator.h:

  struct MemoryAllocator
  {
    ...
  };

  ListRef<byte> AllocateHeap() noexcept;

  namespace global
  {
#if __cplusplus >= 201406
    inline MemoryAllocator _Allocator{AllocateHeap()};
    inline auto& Allocator() noexcept
    {
      return _Allocator;
    }
#else
    inline auto& Allocator() noexcept
    {
      static MemoryAllocator allocator{AllocateHeap()};
      return allocator;
    }
#endif
  }

@DanAlbert
Copy link
Member

Altering your sample so it can actually compile:

struct MemoryAllocator {
  MemoryAllocator() {}
};

inline MemoryAllocator _Allocator{};
inline auto& Allocator() noexcept {
  return _Allocator;
}

Builds fine for me with -std=c++1z. We need a real test case.

@martinbonaciugome
Copy link
Author

martinbonaciugome commented Oct 5, 2017

your test code probably needs to use the allocator in multiple cpp files, or else it will completely get stripped out

@DanAlbert
Copy link
Member

To be blunt, we have plenty of other bugs that need our attention from people that did provide repro cases. It wouldn't be fair to them to give priority to people that put less effort into their bug reports.

@martinbonaciugome
Copy link
Author

also are you sure you went through a full build? because i can't link with -std=c++1z on regardless because of #421. im building with c++14, and ignoring the warning of -Wc++1z-extensions

@martinbonaciugome
Copy link
Author

i dont think you went through the full build process because of #421 with -std=c++1z on. regardless, thanks for taking your time, as i also have my own priorities, and can't spend too much time on this stuff.

@DanAlbert
Copy link
Member

Closing since we don't have a test case after five months and I'm guessing this was just a not yet implemented feature in clang.

@martinbonaciugome
Copy link
Author

just tested on ndk r17-beta1, and i still get linker errors. in my original code, i get "error: undefined reference" to AllocateHeap(), and the constructor of MemoryAllocator. no problems with the _Allocator object. ndk17 has clang 6, which has full support for c++17. apples clang works, and those functions link fine in the c++14 case. project is large and ill see if can find a standalone repro.

@DanAlbert
Copy link
Member

We don't really buave clang 6, we have clang 6 svn, which means we have something between clang 5 and clang 6.

Regardless, there's still nothing we can do about this bug without a test case.

@martinbonaciugome
Copy link
Author

been trying for half the day to try and get a reduced form but i cant repro besides with my exact code in my exact large project.

@martinbonaciugome
Copy link
Author

it might be fixed in a later svn of clang as they fixed a bunch of inline var stuff since the rev you guys build r17 off of.

@martinbonaciugome
Copy link
Author

i do know it is at least related to having a non trivial constructor. if remove the constructor and remove and nontrivial member objects, it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants