From a5f96b68f8af673f7666658f796f2322b6b9da93 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Sun, 27 May 2018 09:05:47 +0200 Subject: String literals are l-values and have array types (#116) * Allow strings literals as lvalues. Strings and WStrings literals are lvalues, thus it is allowed to take their addresses. Bug 23356. * String literals have types "array of (wide) char", not "pointer to (wide) char" The pointer types were a leftover from the early, CIL-based C frontend. * Remove special case for sizeof("string literal") during elaboration No longer needed now that literals have array types. --- cparser/Elab.ml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'cparser/Elab.ml') diff --git a/cparser/Elab.ml b/cparser/Elab.ml index 6923491a..0d9d9d09 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -1765,18 +1765,7 @@ let elab_expr vararg loc env a = error "invalid application of 'sizeof' to an incomplete type %a" (print_typ env) b1.etyp; if wrap is_bitfield loc env b1 then error "invalid application of 'sizeof' to a bit-field"; - let bdesc = - (* Catch special cases sizeof("string literal") *) - match b1.edesc with - | EConst(CStr s) -> - let sz = String.length s + 1 in - EConst(CInt(Int64.of_int sz, size_t_ikind(), "")) - | EConst(CWStr s) -> - let sz = (!config).sizeof_wchar * (List.length s + 1) in - EConst(CInt(Int64.of_int sz, size_t_ikind(), "")) - | _ -> - ESizeof b1.etyp in - { edesc = bdesc; etyp = TInt(size_t_ikind(), []) },env + { edesc = ESizeof b1.etyp; etyp = TInt(size_t_ikind(), []) },env | TYPE_SIZEOF (spec, dcl) -> let (ty, env') = elab_type loc env spec dcl in -- cgit