Implement ES-3.0-specific error semantics for redefining predefined macros.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@29353 e7fa87d3-cd2b-0410-9028-fcbf551c1848
diff --git a/Test/baseResults/cppComplexExpr.vert.out b/Test/baseResults/cppComplexExpr.vert.out
index 0cda42e..100123a 100644
--- a/Test/baseResults/cppComplexExpr.vert.out
+++ b/Test/baseResults/cppComplexExpr.vert.out
@@ -34,8 +34,16 @@
ERROR: 0:156: 'preprocessor evaluation' : undefined macro in expression not allowed in es profile UNDEF2
ERROR: 0:159: 'preprocessor evaluation' : undefined macro in expression not allowed in es profile UNDEF2
ERROR: 0:3000: '#error' : line of this error should be 3000
+ERROR: 0:3002: '#define' : predefined names can't be (un)defined: __LINE__
+ERROR: 0:3003: '#define' : predefined names can't be (un)defined: __FILE__
+ERROR: 0:3004: '#define' : predefined names can't be (un)defined: __VERSION__
+ERROR: 0:3005: '#define' : names beginning with "GL_" can't be (un)defined: GL_SOME_EXTENSION
+ERROR: 0:3006: '#undef' : predefined names can't be (un)defined: __LINE__
+ERROR: 0:3007: '#undef' : predefined names can't be (un)defined: __FILE__
+ERROR: 0:3008: '#undef' : predefined names can't be (un)defined: __VERSION__
+ERROR: 0:3009: '#undef' : names beginning with "GL_" can't be (un)defined: GL_SOME_EXTENSION
ERROR: 0:10001: '' : missing #endif
-ERROR: 36 compilation errors. No code generated.
+ERROR: 44 compilation errors. No code generated.
Shader version: 300
diff --git a/Test/baseResults/cppSimple.vert.out b/Test/baseResults/cppSimple.vert.out
index cbe3c52..2e6a9b4 100644
--- a/Test/baseResults/cppSimple.vert.out
+++ b/Test/baseResults/cppSimple.vert.out
@@ -25,8 +25,8 @@
ERROR: 0:136: '=' : cannot convert from 'const float' to 'int'
ERROR: 0:138: ''' : character literals not supported
ERROR: 0:138: ''' : character literals not supported
-ERROR: 0:141: '#define' : names beginning with "GL_" can't be defined: GL_
-ERROR: 0:142: '#define' : names beginning with "GL_" can't be defined: GL_Macro
+ERROR: 0:141: '#define' : names beginning with "GL_" can't be (un)defined: GL_
+ERROR: 0:142: '#define' : names beginning with "GL_" can't be (un)defined: GL_Macro
WARNING: 0:143: '#define' : names containing consecutive underscores are reserved: __M
WARNING: 0:144: '#define' : names containing consecutive underscores are reserved: M__
WARNING: 0:145: '#define' : names containing consecutive underscores are reserved: ABC__DE
@@ -43,7 +43,7 @@
ERROR: 0:192: '#define' : Macro redefined; different substitutions: m8
ERROR: 0:196: '#define' : Macro redefined; different argument names: m9
WARNING: 0:204: '#undef' : names containing consecutive underscores are reserved: __VERSION__
-ERROR: 0:205: '#undef' : names beginning with "GL_" can't be defined: GL_ARB_texture_rectangle
+ERROR: 0:205: '#undef' : names beginning with "GL_" can't be (un)defined: GL_ARB_texture_rectangle
ERROR: 0:210: '#' : invalid directive
ERROR: 0:211: '#' : invalid directive
ERROR: 0:212: '#' : invalid directive
diff --git a/Test/cppComplexExpr.vert b/Test/cppComplexExpr.vert
index fe01cd5..3f15b5e 100644
--- a/Test/cppComplexExpr.vert
+++ b/Test/cppComplexExpr.vert
@@ -161,6 +161,15 @@
#line 3000
#error line of this error should be 3000
+
+#define __LINE__ 30
+#define __FILE__
+#define __VERSION__
+#define GL_SOME_EXTENSION
+#undef __LINE__
+#undef __FILE__
+#undef __VERSION__
+#undef GL_SOME_EXTENSION
#line 10000
#if 0
diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp
index 0837553..e150c50 100644
--- a/glslang/MachineIndependent/ParseHelper.cpp
+++ b/glslang/MachineIndependent/ParseHelper.cpp
@@ -1783,9 +1783,16 @@
// single underscore) are also reserved, and defining such a name results in a
// compile-time error."
if (strncmp(identifier, "GL_", 3) == 0)
- error(loc, "names beginning with \"GL_\" can't be defined:", op, identifier);
- else if (strstr(identifier, "__") != 0)
- warn(loc, "names containing consecutive underscores are reserved:", op, identifier);
+ error(loc, "names beginning with \"GL_\" can't be (un)defined:", op, identifier);
+ else if (strstr(identifier, "__") != 0) {
+ if (profile == EEsProfile && version >= 300 &&
+ (strcmp(identifier, "__LINE__") == 0 ||
+ strcmp(identifier, "__FILE__") == 0 ||
+ strcmp(identifier, "__VERSION__") == 0))
+ error(loc, "predefined names can't be (un)defined:", op, identifier);
+ else
+ warn(loc, "names containing consecutive underscores are reserved:", op, identifier);
+ }
}
//