shithub: scc

Download patch

ref: ab23974dffb7d6b6b73d65ef7c566e8b6abbd76b
parent: 15cfc88a6819c09e4c93054b31c0be4d48b0aeb0
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jul 5 05:36:38 EDT 2013

Forbid const or volatile in typedef

const or volatile are util only in variable declaration, and can
cause some problems in typedef declarations.

--- a/types.c
+++ b/types.c
@@ -172,6 +172,8 @@
 			goto duplicated;
 		if (tp->c_extern | tp->c_auto | tp->c_reg | tp->c_static)
 			goto two_storage;
+		if (tp->c_const || tp->c_volatile)
+			goto bad_typedef;
 		tp->c_typedef = 1;
 		return tp;
 	case EXTERN:
@@ -209,14 +211,20 @@
 	case CONST:
 		if (options.repeat && tp->c_const)
 			goto duplicated;
+		if (tp->c_typedef)
+			goto bad_typedef;
 		tp->c_const = 1;
 		return tp;
 	case VOLATILE:
 		if (options.repeat && tp->c_volatile)
 			goto duplicated;
+		if (tp->c_typedef)
+			goto bad_typedef;
 		tp->c_volatile = 1;
 		return tp;
 	}
+bad_typedef:
+	error("typedef specifies type qualifier");
 bad_file_scope_storage:
 	error("file-scope declaration specifies '%s'", yytext);
 two_storage:
--