Giter Site home page Giter Site logo

Comments (3)

denisbider avatar denisbider commented on May 17, 2024

It seems challenging to simultaneously compile with no warnings both on C++11 platforms that deprecate auto_ptr, and C++03 platforms that don't have unique_ptr. Is there a way to disable the warning?

from cryptopp.

noloader avatar noloader commented on May 17, 2024

Cleared through a few different commits. Some are listed below.

The general strategy was to identify C++11, identify ancient C++11 standard libraries, and then swap-in unique_ptr for auto_ptr if available. The identification and swap-in occurred in smartptr.h:

// Hack ahead. Apple's standard library does not have C++'s unique_ptr in C++11. We can't
//   test for unique_ptr directly because some of the non-Apple Clangs on OS X fail the same
//   way. However, modern standard libraries have <forward_list>, so we test for it instead.
//   Thanks to Jonathan Wakely for devising the clever test for modern/ancient versions.
// Visual Studio did not add template aliases until VS 2015 (v19.00). Compile failed under
//   Visual Studio 2010 (v16.00) and Visual Studio 2012 (v17.00).
#if (__cplusplus >= 201103L) || (_MSC_VER >= 1900)
#  if defined(__clang__)
#    if (__has_include(<forward_list>))
#      define CRYPTOPP_HAVE_UNIQUE_PTR 1
#    endif
#  else
#    define CRYPTOPP_HAVE_UNIQUE_PTR 1
#  endif
#endif

// The result of below is a CryptoPP::auto_ptr in both cases
#ifdef CRYPTOPP_HAVE_UNIQUE_PTR
  template<typename T>
   using auto_ptr = std::unique_ptr<T>;
#else
  using std::auto_ptr;
#endif

Then, in the source code:

PK_Verifier::VerifyMessage(const byte*, size_t, const byte*, size_t) const
{
    using CryptoPP::auto_ptr;
    auto_ptr<PK_MessageAccumulator> m(NewVerificationAccumulator());
    ...
}

For testing on BSDs, Linux, OS X and Unix, you would build in one of four configurations to ensure correctness:

# c++ -DNDEBUG -g2 -O3 ...
export CXXFLAGS=""
make

# c++ -std=c++11 -DNDEBUG -g2 -O3 ...
export CXXFLAGS="-std=c++11"
make

# c++ -stdlib=libc++ -DNDEBUG -g2 -O3 ...
export CXXFLAGS="-stdlib=libc++"
make

# c++ -std=c++11 -stdlib=libc++ -DNDEBUG -g2 -O3 ...
export CXXFLAGS="-std=c++11 -stdlib=libc++"
make

from cryptopp.

noloader avatar noloader commented on May 17, 2024

It seems challenging to simultaneously compile with no warnings both on C++11 platforms that deprecate auto_ptr, and C++03 platforms that don't have unique_ptr...

This observation was insightful. I found we were able to sidestep most of the warnings by switching to Crypto++'s member_ptr. It provides the same basic functionality we needed, and it has both reset and release. It does not require the [sometimes] convoluted logic to determine when C++11 is really available, and does not require template declaration support.

We have one place we could not cleanly cut over, and that was in validat1.cpp (around line 575). So warnings went from "a lot" to "just one".

from cryptopp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.