Disallow implicit conversions from None to integer types
authorJustin Bogner <mail@justinbogner.com>
Fri, 20 Feb 2015 07:28:28 +0000 (07:28 +0000)
committerJustin Bogner <mail@justinbogner.com>
Fri, 20 Feb 2015 07:28:28 +0000 (07:28 +0000)
This fixes an error introduced in r228934 where None was converted to
an int instead of the int being converted to an Optional as intended.
We make that sort of mistake a compile error by changing NoneType into
a scoped enum.

Finally, provide a static NoneType called None to avoid forcing all
users to spell it NoneType::None.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229980 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/None.h
lib/ProfileData/CoverageMapping.cpp

index 5793bd2faef404a3d852cda2b39047e301100928..c78db78597cc681946a925014ccbb10e5565939e 100644 (file)
@@ -19,9 +19,8 @@
 namespace llvm {
 /// \brief A simple null object to allow implicit construction of Optional<T>
 /// and similar types without having to spell out the specialization's name.
-enum NoneType {
-  None
-};
+enum class NoneType { None };
+static NoneType None;
 }
 
 #endif
index a124d792e8752b0290df1fe737b07aa6ca284135..da619e1bf9f8d299307fb7735196657f4a490cf9 100644 (file)
@@ -361,7 +361,9 @@ static Optional<unsigned> findMainViewFileID(StringRef SourceFile,
       IsNotExpandedFile[CR.ExpandedFileID] = false;
   IsNotExpandedFile &= FilenameEquivalence;
   int I = IsNotExpandedFile.find_first();
-  return I != -1 ? I : None;
+  if (I == -1)
+    return None;
+  return I;
 }
 
 static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) {
@@ -370,7 +372,9 @@ static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) {
     if (CR.Kind == CounterMappingRegion::ExpansionRegion)
       IsNotExpandedFile[CR.ExpandedFileID] = false;
   int I = IsNotExpandedFile.find_first();
-  return I != -1 ? I : None;
+  if (I == -1)
+    return None;
+  return I;
 }
 
 /// Sort a nested sequence of regions from a single file.