Hi revane, arielbernal, tareqsiraj,
Note that this patch assume that this one has been accepted first:
http://llvm-reviews.chandlerc.com/D1196
The new command line switch '-supports' introduced by this patch allows the user
to enable multiple transforms automatically based on some requirements about the
compiler versions.
Such as:
cpp11-migrate -supports clang-3.0 <args...>
This enable all transforms supported by the Clang since the version 3.0.
For reference this was the old implementation but changes have been requested:
http://llvm-reviews.chandlerc.com/D1154
http://llvm-reviews.chandlerc.com/D1202
Files:
cpp11-migrate/AddOverride/AddOverride.cpp
cpp11-migrate/Core/Transform.cpp
cpp11-migrate/Core/Transform.h
cpp11-migrate/Core/Transforms.cpp
cpp11-migrate/Core/Transforms.h
cpp11-migrate/LoopConvert/LoopConvert.cpp
cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtr.cpp
cpp11-migrate/UseAuto/UseAuto.cpp
cpp11-migrate/UseNullptr/UseNullptr.cpp
cpp11-migrate/tool/Cpp11Migrate.cpp
docs/MigratorUsage.rst
test/cpp11-migrate/Combined/compilers.cpp
Index: cpp11-migrate/AddOverride/AddOverride.cpp
===================================================================
--- cpp11-migrate/AddOverride/AddOverride.cpp
+++ cpp11-migrate/AddOverride/AddOverride.cpp
@@ -61,6 +61,18 @@
}
struct AddOverrideFactory : TransformFactory {
+ AddOverrideFactory() {
+ // if detecting macros is enabled, do not impose requirements on the
+ // compiler. It is assumed that the macros use is "C++11-aware", meaning it
+ // won't expand to override if the compiler doesn't support the specifier.
+ if (!DetectMacros) {
+ Since.Clang = Version(3, 0);
+ Since.Gcc = Version(4, 7);
+ Since.Icc = Version(14);
+ Since.Msvc = Version(8);
+ }
+ }
+
Transform *createTransform(const TransformOptions &Opts) LLVM_OVERRIDE {
return new AddOverrideTransform(Opts);
}
Index: cpp11-migrate/Core/Transform.cpp
===================================================================
--- cpp11-migrate/Core/Transform.cpp
+++ cpp11-migrate/Core/Transform.cpp
@@ -20,6 +20,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
using namespace clang;
@@ -133,4 +134,32 @@
return new ActionFactory(Finder, /*Owner=*/ *this);
}
+Version Version::getFromString(llvm::StringRef VersionStr) {
+ llvm::StringRef MajorStr, MinorStr;
+ Version V;
+
+ llvm::tie(MajorStr, MinorStr) = VersionStr.split('.');
+ if (!MinorStr.empty() && MinorStr.getAsInteger(10, V.Minor))
+ return Version();
+ if (MajorStr.getAsInteger(10, V.Major))
+ return Version();
+ return V;
+}
+
TransformFactory::~TransformFactory() {}
+
+namespace {
+bool versionSupported(Version Required, Version AvailableSince) {
+ // null version, means no requirements, means supported
+ if (Required.isNull())
+ return true;
+ return Required >= AvailableSince;
+}
+} // end anonymous namespace
+
+bool TransformFactory::supportsRequirements(CompilerVersions Required) const {
+ return versionSupported(Required.Clang, Since.Clang) &&
+ versionSupported(Required.Gcc, Since.Gcc) &&
+ versionSupported(Required.Icc, Since.Icc) &&
+ versionSupported(Required.Msvc, Since.Msvc);
+}
Index: cpp11-migrate/Core/Transform.h
===================================================================
--- cpp11-migrate/Core/Transform.h
+++ cpp11-migrate/Core/Transform.h
@@ -71,6 +71,9 @@
/// \brief Maximum allowed level of risk.
RiskLevel MaxRiskLevel;
+
+ /// \brief Whether all transforms should be enabled by default or not.
+ bool EnableAllTransformByDefault;
};
/// \brief Abstract base class for all C++11 migration transforms.
@@ -222,17 +225,72 @@
unsigned DeferredChanges;
};
+/// \brief Describes a version number of the form major[.minor] (minor being
+/// optional).
+struct Version {
+ explicit Version(unsigned Major = 0, unsigned Minor = 0)
+ : Major(Major), Minor(Minor) {}
+
+ bool operator<(Version RHS) const {
+ if (Major < RHS.Major)
+ return true;
+ if (Major == RHS.Major)
+ return Minor < RHS.Minor;
+ return false;
+ }
+
+ bool operator==(Version RHS) const {
+ return Major == RHS.Major && Minor == RHS.Minor;
+ }
+
+ bool operator!=(Version RHS) const { return !(*this == RHS); }
+ bool operator>(Version RHS) const { return RHS < *this; }
+ bool operator<=(Version RHS) const { return !(*this > RHS); }
+ bool operator>=(Version RHS) const { return !(*this < RHS); }
+
+ bool isNull() const { return Minor == 0 && Major == 0; }
+ unsigned getMajor() const { return Major; }
+ unsigned getMinor() const { return Minor; }
+
+ /// \brief Creates a version from a string of the form \c MAJOR[.MINOR].
+ ///
+ /// \return A null version is returned on error.
+ static Version getFromString(llvm::StringRef VersionStr);
+
+private:
+ unsigned Major;
+ unsigned Minor;
+};
+
+/// \brief Convenience structure to store the version of some compilers.
+struct CompilerVersions {
+ Version Clang, Gcc, Icc, Msvc;
+};
+
/// \brief A factory that can instantiate a specific transform.
///
/// Each transform should subclass it and implement the \c createTransform()
-/// methods. Use \c TransformFactoryRegistry to register the transform globally.
+/// method.
///
+/// Some constraints can informed about the compiler versions supported by the
+/// transform. These constraints should be set in the constructor as show in the
+/// example.
+///
+/// Note that you should use \c TransformFactoryRegistry to register the
+/// transform globally.
///
/// Example:
/// \code
/// class MyTransform : public Transform { ... };
///
/// struct MyFactory : TransformFactory {
+/// MyFactory() {
+/// Since.Clang = Version(3, 0);
+/// Since.Gcc = Version(4, 7);
+/// Since.Icc = Version(12);
+/// Since.Msvc = Version(10);
+/// }
+///
/// Transform *createTransform(const TransformOptions &Opts) LLVM_OVERRIDE {
/// return new MyTransform(Opts);
/// }
@@ -250,6 +308,16 @@
public:
virtual ~TransformFactory();
virtual Transform *createTransform(const TransformOptions &) = 0;
+
+ /// \brief Whether the transform is supported by the required compilers or
+ /// not.
+ bool supportsRequirements(CompilerVersions Required) const;
+
+protected:
+ /// \brief Since when this transform is available.
+ ///
+ /// Can be set by the sub-class in the constructor body.
+ CompilerVersions Since;
};
typedef llvm::Registry<TransformFactory> TransformFactoryRegistry;
Index: cpp11-migrate/Core/Transforms.cpp
===================================================================
--- cpp11-migrate/Core/Transforms.cpp
+++ cpp11-migrate/Core/Transforms.cpp
@@ -38,16 +38,19 @@
}
void
-Transforms::createSelectedTransforms(const TransformOptions &GlobalOptions) {
+Transforms::createSelectedTransforms(const TransformOptions &GlobalOptions,
+ const CompilerVersions &RequiredVersions) {
for (TransformFactoryRegistry::iterator I = TransformFactoryRegistry::begin(),
E = TransformFactoryRegistry::end();
I != E; ++I) {
- bool OptionEnabled = *Options[I->getName()];
+ bool OptionEnabled =
+ GlobalOptions.EnableAllTransformByDefault || *Options[I->getName()];
if (!OptionEnabled)
continue;
llvm::OwningPtr<TransformFactory> Factory(I->instantiate());
- ChosenTransforms.push_back(Factory->createTransform(GlobalOptions));
+ if (Factory->supportsRequirements(RequiredVersions))
+ ChosenTransforms.push_back(Factory->createTransform(GlobalOptions));
}
}
Index: cpp11-migrate/Core/Transforms.h
===================================================================
--- cpp11-migrate/Core/Transforms.h
+++ cpp11-migrate/Core/Transforms.h
@@ -30,6 +30,7 @@
} // namespace llvm
class Transform;
struct TransformOptions;
+struct CompilerVersions;
typedef Transform *(*TransformCreator)(const TransformOptions &);
template <typename T>
@@ -57,7 +58,8 @@
/// \brief Instantiate all transforms that were selected on the command line.
///
/// Call *after* parsing options.
- void createSelectedTransforms(const TransformOptions &Options);
+ void createSelectedTransforms(const TransformOptions &Options,
+ const CompilerVersions &RequiredVersions);
/// \brief Return an iterator to the start of a container of instantiated
/// transforms.
Index: cpp11-migrate/LoopConvert/LoopConvert.cpp
===================================================================
--- cpp11-migrate/LoopConvert/LoopConvert.cpp
+++ cpp11-migrate/LoopConvert/LoopConvert.cpp
@@ -68,6 +68,13 @@
}
struct LoopConvertFactory : TransformFactory {
+ LoopConvertFactory() {
+ Since.Clang = Version(3, 0);
+ Since.Gcc = Version(4, 6);
+ Since.Icc = Version(13);
+ Since.Msvc = Version(11);
+ }
+
Transform *createTransform(const TransformOptions &Opts) LLVM_OVERRIDE {
return new LoopConvertTransform(Opts);
}
Index: cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtr.cpp
===================================================================
--- cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtr.cpp
+++ cpp11-migrate/ReplaceAutoPtr/ReplaceAutoPtr.cpp
@@ -50,6 +50,13 @@
}
struct ReplaceAutoPtrFactory : TransformFactory {
+ ReplaceAutoPtrFactory() {
+ Since.Clang = Version(3, 0);
+ Since.Gcc = Version(4, 6);
+ Since.Icc = Version(13);
+ Since.Msvc = Version(11);
+ }
+
Transform *createTransform(const TransformOptions &Opts) LLVM_OVERRIDE {
return new ReplaceAutoPtrTransform(Opts);
}
Index: cpp11-migrate/UseAuto/UseAuto.cpp
===================================================================
--- cpp11-migrate/UseAuto/UseAuto.cpp
+++ cpp11-migrate/UseAuto/UseAuto.cpp
@@ -49,6 +49,13 @@
}
struct UseAutoFactory : TransformFactory {
+ UseAutoFactory() {
+ Since.Clang = Version(2, 9);
+ Since.Gcc = Version(4, 4);
+ Since.Icc = Version(12);
+ Since.Msvc = Version(10);
+ }
+
Transform *createTransform(const TransformOptions &Opts) LLVM_OVERRIDE {
return new UseAutoTransform(Opts);
}
Index: cpp11-migrate/UseNullptr/UseNullptr.cpp
===================================================================
--- cpp11-migrate/UseNullptr/UseNullptr.cpp
+++ cpp11-migrate/UseNullptr/UseNullptr.cpp
@@ -50,6 +50,13 @@
}
struct UseNullptrFactory : TransformFactory {
+ UseNullptrFactory() {
+ Since.Clang = Version(3, 0);
+ Since.Gcc = Version(4, 6);
+ Since.Icc = Version(12, 1);
+ Since.Msvc = Version(10);
+ }
+
Transform *createTransform(const TransformOptions &Opts) LLVM_OVERRIDE {
return new UseNullptrTransform(Opts);
}
Index: cpp11-migrate/tool/Cpp11Migrate.cpp
===================================================================
--- cpp11-migrate/tool/Cpp11Migrate.cpp
+++ cpp11-migrate/tool/Cpp11Migrate.cpp
@@ -20,9 +20,12 @@
#include "Core/SyntaxCheck.h"
#include "Core/Transform.h"
#include "Core/Transforms.h"
+#include "Core/Reformatting.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Signals.h"
@@ -112,6 +115,78 @@
cl::location(GlobalOptions.EnableHeaderModifications),
cl::init(false));
+cl::list<std::string> Supports(
+ "supports", cl::value_desc("platform"), cl::ZeroOrMore,
+ cl::desc(
+ "Add a platform to be supported by the migration.\n"
+ "All transforms supported by all of the given platforms"
+ " will be used for the migration.\n"
+ "Currently supports:\n"
+ "\tc++11, clang-VERSION, gcc-VERSION, icc-VERSION and msvc-VERSION\n"
+ "where VERSION is MAJOR[.MINOR], example:\n"
+ "\tcpp11-migrate -toward clang-3.1 -toward gcc-4.7 -toward icc-12.1 "
+ "-toward msvc-11 <args...>"));
+
+/// \brief Extract the minimum compiler versions as requested on the command
+/// line by the switch \c -supports.
+///
+/// \param ProgName The name of the program, \c argv[0], used to print errors.
+/// \param Error If an error occur while parsing the versions this parameter is
+/// set to \c true, otherwise it will be left untouched.
+static CompilerVersions handleSupportsCommand(const char *ProgName,
+ bool &Error) {
+ CompilerVersions RequiredVersions;
+
+ GlobalOptions.EnableAllTransformByDefault = false;
+ for (std::vector<std::string>::iterator I = Supports.begin(),
+ E = Supports.end();
+ I != E; ++I) {
+ llvm::StringRef Platform = *I;
+
+ // If c++11 is specified or if a compiler version is required, enable all
+ // transforms by default.
+ GlobalOptions.EnableAllTransformByDefault = true;
+
+ // check for c++11
+ if (Platform == "c++11")
+ continue;
+
+ // otherwise assume "plaform-version" format
+ llvm::StringRef VersionStr;
+ llvm::tie(Platform, VersionStr) = Platform.split('-');
+
+ Version *V = llvm::StringSwitch<Version *>(Platform)
+ .Case("clang", &RequiredVersions.Clang)
+ .Case("gcc", &RequiredVersions.Gcc).Case("icc", &RequiredVersions.Icc)
+ .Case("msvc", &RequiredVersions.Msvc).Default(NULL);
+
+ if (V == NULL) {
+ llvm::errs() << ProgName << ": " << Platform
+ << ": unsupported platform\n";
+ Error = true;
+ continue;
+ }
+ if (VersionStr.empty()) {
+ llvm::errs() << ProgName << ": " << *I
+ << ": missing version number in platform\n";
+ Error = true;
+ continue;
+ }
+
+ Version Version = Version::getFromString(VersionStr);
+ if (Version.isNull()) {
+ llvm::errs() << ProgName << ": " << Platform << ": invalid version "
+ << VersionStr << "\n";
+ Error = true;
+ continue;
+ }
+ // support the lowest version given
+ if (V->isNull() || Version < *V)
+ *V = Version;
+ }
+ return RequiredVersions;
+}
+
/// \brief Creates the Reformatter if the format style option is provided,
/// return a null pointer otherwise.
///
@@ -160,10 +235,13 @@
GlobalOptions.EnableTiming = (TimingDirectoryName != NoTiming);
// Check the reformatting style option
- bool BadStyle = false;
+ bool CmdSwitchError = false;
llvm::OwningPtr<Reformatter> ChangesReformatter(
- handleFormatStyle(argv[0], BadStyle));
- if (BadStyle)
+ handleFormatStyle(argv[0], CmdSwitchError));
+
+ CompilerVersions RequiredVersions =
+ handleSupportsCommand(argv[0], CmdSwitchError);
+ if (CmdSwitchError)
return 1;
// Populate the ModifiableHeaders structure if header modifications are
@@ -175,7 +253,7 @@
.readListFromFile(IncludeFromFile, ExcludeFromFile);
}
- TransformManager.createSelectedTransforms(GlobalOptions);
+ TransformManager.createSelectedTransforms(GlobalOptions, RequiredVersions);
if (TransformManager.begin() == TransformManager.end()) {
llvm::errs() << argv[0] << ": No selected transforms\n";
@@ -271,3 +349,18 @@
return 0;
}
+
+// These anchors are used to force the linker to link the transforms
+extern volatile int AddOverrideTransformAnchorSource;
+extern volatile int LoopConvertTransformAnchorSource;
+extern volatile int ReplaceAutoPtrTransformAnchorSource;
+extern volatile int UseAutoTransformAnchorSource;
+extern volatile int UseNullptrTransformAnchorSource;
+
+static int TransformsAnchorsDestination[] = {
+ AddOverrideTransformAnchorSource,
+ LoopConvertTransformAnchorSource,
+ ReplaceAutoPtrTransformAnchorSource,
+ UseAutoTransformAnchorSource,
+ UseNullptrTransformAnchorSource
+};
Index: docs/MigratorUsage.rst
===================================================================
--- docs/MigratorUsage.rst
+++ docs/MigratorUsage.rst
@@ -113,6 +113,56 @@
with other accepted changes. Re-applying the transform will resolve deferred
changes.
+.. option:: -supports <platform>
+
+ Select the platforms to support. The transforms will be selected automatically
+ to work on all selected platform.
+
+ There is a special platform **c++11** that enables all transforms.
+
+ ``cpp11-migrate -supports c++11 <args..>``
+
+
+ And four compilers are supported. The transforms are enabled according to this
+ table:
+
+ =============== ===== === ==== ====
+ Transforms clang gcc icc mscv
+ =============== ===== === ==== ====
+ AddOverride (1) 3.0 4.7 14 8
+ LoopConvert 3.0 4.6 13 11
+ ReplaceAutoPtr 3.0 4.6 13 11
+ UseAuto 2.9 4.4 12 10
+ UseNullptr 3.0 4.6 12.1 10
+ =============== ===== === ==== ====
+
+ (1): if *-override-macros* is provided it's assumed that the macros is C++11
+ aware and the transform is enabled without regard to the supported compilers.
+
+ The version has to be provided like this `-supports [COMPILER]-[VERSION]`.
+
+ Some examples:
+
+ 1. If we want to support `Clang >= 3`, `GCC >= 4.6` and `MSVC >= 11`:
+
+ ``cpp11-migrate -supports clang-3.0 -supports gcc-4.6 -supports msvc-11
+ <args..>``
+
+ Enables LoopConvert, ReplaceAutoPtr, UseAuto, UseNullptr.
+
+ 2. If we want to support `icc >= 12` and a C++11-aware macro exists for the
+ `override` identifier:
+
+ ``cpp11-migrate -supports icc-12 -override-macros <args..>``
+
+ Enables AddOverride and UseAuto.
+
+ .. warning::
+
+ If your version of Clang depends on the GCC headers (e.g: when `libc++` is
+ not used), then you probably want to add the GCC version to the targeted
+ platforms as well.
+
.. option:: -perf[=<directory>]
Turns on performance measurement and output functionality. The time it takes to
Index: test/cpp11-migrate/Combined/compilers.cpp
===================================================================
--- /dev/null
+++ test/cpp11-migrate/Combined/compilers.cpp
@@ -0,0 +1,141 @@
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports c++11 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=CPP11 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports clang-2.9 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=CLANG-29 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports clang-2.9 -override-macros %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=CLANG-29-OV-MACROS -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports clang-3.0 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=CLANG-30 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports gcc-4.4 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=GCC-44 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports gcc-4.6 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=GCC-46 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports gcc-4.7 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=GCC-47 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports icc-12 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=ICC-12 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports icc-12.1 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=ICC-121 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports icc-13 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=ICC-13 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports icc-14 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=ICC-14 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports msvc-8 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=MSVC-8 -input-file=%t.cpp %s
+//
+// RUN: grep -Ev "// *[A-Z0-9-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -supports msvc-11 %t.cpp -- -std=c++11
+// RUN: FileCheck -check-prefix=MSVC-11 -input-file=%t.cpp %s
+
+// Test add overrides
+struct A {
+ virtual A *clone() = 0;
+};
+
+#define LLVM_OVERRIDE override
+
+struct B : A {
+ virtual B *clone();
+ // CPP11: virtual B *clone() override;
+ // CLANG-29-OV-MACROS: virtual B *clone() LLVM_OVERRIDE;
+ // CLANG-29: virtual B *clone();
+ // CLANG-30: virtual B *clone() override;
+ // GCC-46: virtual B *clone();
+ // GCC-47: virtual B *clone() override;
+ // ICC-13: virtual B *clone();
+ // ICC-14: virtual B *clone() override;
+ // MSVC-8: virtual B *clone() override;
+};
+
+// Test loop-convert
+void pass(int);
+void f_1() {
+int arr[] = {1,2,3};
+ for (int i = 0; i < 3; ++i)
+ pass(arr[i]);
+ // CPP11: for (auto & elem : arr)
+ // CPP11-NEXT: pass(elem);
+ // CLANG-29: for (int i = 0; i < 3; ++i)
+ // CLANG-29-NEXT: pass(arr[i]);
+ // CLANG-30: for (auto & elem : arr)
+ // CLANG-30-NEXT: pass(elem);
+ // GCC-44: for (int i = 0; i < 3; ++i)
+ // GCC-44-NEXT: pass(arr[i]);
+ // GCC-46: for (auto & elem : arr)
+ // GCC-46-NEXT: pass(elem);
+ // ICC-12: for (int i = 0; i < 3; ++i)
+ // ICC-12-NEXT: pass(arr[i]);
+ // ICC-13: for (auto & elem : arr)
+ // ICC-13-NEXT: pass(elem);
+ // MSVC-8: for (int i = 0; i < 3; ++i)
+ // MSVC-8-NEXT: pass(arr[i]);
+ // MSVC-11: for (auto & elem : arr)
+ // MSVC-11-NEXT: pass(elem);
+}
+
+// Test replace auto-ptr
+namespace std {
+template <class T> class auto_ptr {};
+template <class T> class unique_ptr {};
+}
+void f_2() {
+ std::auto_ptr<int> s;
+ // CPP11: std::unique_ptr<int> s;
+ // CLANG-29: std::auto_ptr<int> s;
+ // CLANG-30: std::unique_ptr<int> s;
+ // GCC-44: std::auto_ptr<int> s;
+ // GCC-46: std::unique_ptr<int> s;
+ // ICC-12: std::auto_ptr<int> s;
+ // ICC-13: std::unique_ptr<int> s;
+ // MSVC-8: std::auto_ptr<int> s;
+ // MSVC-11: std::unique_ptr<int> s;
+}
+
+// Test use auto
+struct MyType {};
+void f_3() {
+ MyType *a = new MyType();
+ // CPP11: auto a = new MyType();
+ // CLANG-29: auto a = new MyType();
+ // GCC-44: auto a = new MyType();
+ // ICC-12: auto a = new MyType();
+ // MSVC-8: MyType *a = new MyType();
+ // MSVC-10: auto a = new MyType();
+}
+
+// Test use nullptr
+void f_4() {
+ int *p = 0;
+ // CPP11: int *p = nullptr;
+ // CLANG-29: int *p = 0;
+ // CLANG-30: int *p = nullptr;
+ // GCC-4.4: int *p = 0;
+ // GCC-4.6: int *p = nullptr;
+ // ICC-12: int *p = 0;
+ // ICC-121: int *p = nullptr;
+ // MSVC-8: int *p = 0;
+ // MSVC-10: int *p = nullptr;
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits