KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
3.03k stars 833 forks source link

hlslParseables.cpp:148:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses] #383

Closed fbarchard closed 8 years ago

fbarchard commented 8 years ago

[834/2757] CXX obj/dreamos/external/glslang/glslang/hlslParseables.o ../../../../../../dreamos/external/glslang/hlsl/hlslParseables.cpp: In function 'glslang::TString& {anonymous}::AppendTypeName(glslang::TString&, const char, const char, int, int)': ../../../../../../dreamos/external/glslang/hlsl/hlslParseables.cpp:112:48: warning: suggest parentheses around '&&' within '||' [-Wparentheses] if ((argOrder == 'V' || *argOrder == 'M') && (dim0 < 1 || dim0 > 4) || ^ ../../../../../../dreamos/external/glslang/hlsl/hlslParseables.cpp: In function 'bool {anonymous}::IsValidGlsl(const char, char, char, char, char, int, int, int, int)': ../../../../../../dreamos/external/glslang/hlsl/hlslParseables.cpp:148:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses] if (isMat && (argType == 'I' || argType == 'U' || argType == 'B') || ^ At global scope:

The patch below adds parentheses and removes trailing spaces:

diff --git a/hlsl/hlslParseables.cpp b/hlsl/hlslParseables.cpp
index 18f7ca4..1849103 100755
@@ -108,8 +108,8 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
         }
     }

-    // verify dimensions
-    if ((*argOrder == 'V' || *argOrder == 'M') && (dim0 < 1 || dim0 > 4) ||
+    // Verify dimensions.
+    if (((*argOrder == 'V' || *argOrder == 'M') && (dim0 < 1 || dim0 > 4)) ||
         (*argOrder == 'M' && (dim1 < 1 || dim1 > 4))) {
         s += "UNKNOWN_DIMENSION";
         return s;
@@ -141,12 +141,12 @@ inline bool IsValidGlsl(const char* cname, char retOrder, char retType, char arg
         return false;

     const std::string name(cname);  // for ease of comparison. slow, but temporary, until HLSL parser is online.
-                                
+
     if (isMat && dim0 != dim1)  // TODO: avoid mats until we find the right GLSL profile
         return false;

-    if (isMat && (argType == 'I' || argType == 'U' || argType == 'B') ||
-        retOrder == 'M' && (retType == 'I' || retType == 'U' || retType == 'B'))
+    if ((isMat && (argType == 'I' || argType == 'U' || argType == 'B')) ||
+        (retOrder == 'M' && (retType == 'I' || retType == 'U' || retType == 'B')))
         return false;

     if (name == "GetRenderTargetSamplePosition" ||
ghost commented 8 years ago

Thanks fbarchard... I have a pending PR #380 for some texture sampling work, and folded your warning fixes above into that.

(I added it to that PR because it's touching the same lines of code for other reasons anyway.)