Validate main() prototype declarations with incorrect parameters
Instead of just validating definitions of main(), do the validation
for all function headers for functions named "main", including headers
in prototype declarations.
BUG=angleproject:1712
TEST=angle_unittests
Change-Id: Ia34a2a756e1cc27b241b27e8c01c6ef09bffba71
Reviewed-on: https://chromium-review.googlesource.com/430010
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index a42ee87..edeadb5 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -2530,21 +2530,6 @@
(*function)->setDefined();
}
- // Raise error message if main function takes any parameters or return anything other than void
- if ((*function)->getName() == "main")
- {
- if ((*function)->getParamCount() > 0)
- {
- error(location, "function cannot take any parameter(s)",
- (*function)->getName().c_str());
- }
- if ((*function)->getReturnType().getBasicType() != EbtVoid)
- {
- error(location, "main function cannot return a value",
- (*function)->getReturnType().getBasicString());
- }
- }
-
// Remember the return type for later checking for return statements.
mCurrentFunctionType = &((*function)->getReturnType());
mFunctionReturnsValue = false;
@@ -2615,6 +2600,20 @@
// Add the function prototype to the surrounding scope instead.
symbolTable.getOuterLevel()->insert(function);
+ // Raise error message if main function takes any parameters or return anything other than void
+ if (function->getName() == "main")
+ {
+ if (function->getParamCount() > 0)
+ {
+ error(location, "function cannot take any parameter(s)", "main");
+ }
+ if (function->getReturnType().getBasicType() != EbtVoid)
+ {
+ error(location, "main function cannot return a value",
+ function->getReturnType().getBasicString());
+ }
+ }
+
//
// If this is a redeclaration, it could also be a definition, in which case, we want to use the
// variable names from this one, and not the one that's