[PATCH] D62259: shared_ptr changes from library fundamentals (P0414R2)

Joseph Southwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 3 10:28:37 PDT 2021


cedral added a comment.

using static_assert breaks the ability to include <memory> in a precompiled header and then explicitly define a shared pointer type for export. You should have used enable_if on the return type instead.  you can download my Xcode 12 project files from southwell.org <http://southwell.org/testtemplate.zip> or create your own based on the following three code files. test.cpp will fail to compile because it attempts to instantiate the [] lookup operator for export. I don't think this is a bug. It needs to do this because it doesn't know which member functions will be called when the exported type is used by clients of the library. Though this does appear to work if memory is not first included in a precompiled header so I could be misinterpreting that.

PrefixHeader.pch

  #include <memory>

test.hpp

  #ifndef testtemplate_
  #define testtemplate_
  
  #include <memory>
  
  template class __attribute__ ((visibility ("default"))) std::shared_ptr<int>;
  
  typedef std::shared_ptr<int> shared_int;
  
  __attribute__ ((visibility ("default"))) shared_int get_int();
  
  #endif

test.cpp

  #include "testtemplate.hpp"
  #include <cstdlib>
  
  shared_int get_int()
  {
    return std::make_shared<int>(std::rand());
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62259/new/

https://reviews.llvm.org/D62259



More information about the llvm-commits mailing list