geirg71 commented on issue #177:
URL: 
https://github.com/apache/logging-log4cxx/issues/177#issuecomment-1383078063

   Thank you for the lightning fast response Stephen. Your 2 commits fix my 
problem on MSYS2.
   
   I do however ask you to look at the use of the 
LOG4CXX_INSTANTIATE_EXPORTED_PTR macro. Clang 14 on Linux complains about the 
same issue as GCC if I change the macro to the Windows variant (refer output 
below). Hence I guess the C++ standard really prohibits this type of template 
instantiations, and the issue could resurface later in e.g. future MSVC 
versions implementing the standard.
   
   For me both compilers are happy if I move LOG4CXX_INSTANTIATE_EXPORTED_PTR 
outside of the log4cxx namespace. Example from propertysetter.h, change: 
   
   ```
   #include <log4cxx/logstring.h>
   #include <log4cxx/helpers/object.h>
   
   namespace log4cxx
   {
   namespace helpers
   {
   class Object;
   // Instantiate template pointer type passed as parameter
   LOG4CXX_INSTANTIATE_EXPORTED_PTR(Object);
   LOG4CXX_PTR_DEF(Object);
   ```
   
   to
   
   ```
   #include <log4cxx/logstring.h>
   #include <log4cxx/helpers/object.h>
   
   // Instantiate template pointer type passed as parameter
   LOG4CXX_INSTANTIATE_EXPORTED_PTR(log4cxx::helpers::Object);
   
   namespace log4cxx
   {
   namespace helpers
   {
   class Object;
   LOG4CXX_PTR_DEF(Object);
   ```
   
   Clang 14 on Ubuntu 22.04 with #define LOG4CXX_INSTANTIATE_EXPORTED_PTR(T) 
template class LOG4CXX_EXPORT std::shared_ptr<T>:
   ```
   $ clang++ --version
   Ubuntu clang version 14.0.0-1ubuntu1
   Target: x86_64-pc-linux-gnu
   Thread model: posix
   InstalledDir: /usr/bin
   
   [build] /usr/bin/clang++  -Ilogging-log4cxx/src/test/cpp/util 
-Ilogging-log4cxx/build/src/main/include -Ilogging-log4cxx/src/main/include 
-I/usr/include/apr-1.0 -g -std=c++17 -MD -MT 
src/test/cpp/util/CMakeFiles/testingUtilities.dir/compare.cpp.o -MF 
src/test/cpp/util/CMakeFiles/testingUtilities.dir/compare.cpp.o.d -o 
src/test/cpp/util/CMakeFiles/testingUtilities.dir/compare.cpp.o -c 
logging-log4cxx/src/test/cpp/util/compare.cpp
   [build] In file included from 
logging-log4cxx/src/test/cpp/util/compare.cpp:23:
   [build] 
logging-log4cxx/src/main/include/log4cxx/helpers/inputstreamreader.h:32:1: 
error: explicit instantiation of 'shared_ptr' not in a namespace enclosing 'std'
   [build] LOG4CXX_INSTANTIATE_EXPORTED_PTR(InputStream);
   [build] ^
   [build] logging-log4cxx/build/src/main/include/log4cxx/log4cxx.h:94:80: 
note: expanded from macro 'LOG4CXX_INSTANTIATE_EXPORTED_PTR'
   [build] #define LOG4CXX_INSTANTIATE_EXPORTED_PTR(T) template class 
LOG4CXX_EXPORT std::shared_ptr<T>
   [build]                                                                      
          ^
   [build] 
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/shared_ptr.h:175:11:
 note: explicit instantiation refers here
   [build]     class shared_ptr : public __shared_ptr<_Tp>
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to