Disallow implicit conversions from None to integer types

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.

llvm-svn: 229980
This commit is contained in:
Justin Bogner 2015-02-20 07:28:28 +00:00
parent b73c041005
commit c4f5a5e863
2 changed files with 8 additions and 5 deletions

View File

@ -19,9 +19,8 @@
namespace llvm { namespace llvm {
/// \brief A simple null object to allow implicit construction of Optional<T> /// \brief A simple null object to allow implicit construction of Optional<T>
/// and similar types without having to spell out the specialization's name. /// and similar types without having to spell out the specialization's name.
enum NoneType { enum class NoneType { None };
None static NoneType None;
};
} }
#endif #endif

View File

@ -361,7 +361,9 @@ static Optional<unsigned> findMainViewFileID(StringRef SourceFile,
IsNotExpandedFile[CR.ExpandedFileID] = false; IsNotExpandedFile[CR.ExpandedFileID] = false;
IsNotExpandedFile &= FilenameEquivalence; IsNotExpandedFile &= FilenameEquivalence;
int I = IsNotExpandedFile.find_first(); int I = IsNotExpandedFile.find_first();
return I != -1 ? I : None; if (I == -1)
return None;
return I;
} }
static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) { static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) {
@ -370,7 +372,9 @@ static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) {
if (CR.Kind == CounterMappingRegion::ExpansionRegion) if (CR.Kind == CounterMappingRegion::ExpansionRegion)
IsNotExpandedFile[CR.ExpandedFileID] = false; IsNotExpandedFile[CR.ExpandedFileID] = false;
int I = IsNotExpandedFile.find_first(); 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. /// Sort a nested sequence of regions from a single file.