NamedEnum: Check range of names array index to avoid warning from gcc
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -120,4 +120,25 @@ Foam::wordList Foam::NamedEnum<Enum, nEnum>::words()
|
||||
}
|
||||
|
||||
|
||||
template<class Enum, unsigned int nEnum>
|
||||
const char* Foam::NamedEnum<Enum, nEnum>::operator[](const Enum e) const
|
||||
{
|
||||
unsigned int ue = unsigned(e);
|
||||
|
||||
if (ue < nEnum)
|
||||
{
|
||||
return names[ue];
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "names array index " << ue << " out of range 0-"
|
||||
<< nEnum - 1
|
||||
<< exit(FatalError);
|
||||
|
||||
return names[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -38,7 +38,6 @@ SourceFiles
|
||||
#include "HashTable.H"
|
||||
#include "stringList.H"
|
||||
#include "wordList.H"
|
||||
#include <type_traits>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -108,10 +107,7 @@ public:
|
||||
}
|
||||
|
||||
//- Return the name of the given enumeration element
|
||||
const char* operator[](const Enum e) const
|
||||
{
|
||||
return names[unsigned(e)];
|
||||
}
|
||||
const char* operator[](const Enum e) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user