From 274fe375264e1767a8dcaea06eaa5d6735e32e37 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 19 Mar 2013 01:10:28 +0100 Subject: rewritten CHR2STR() using compound statement * fixes compilation on g++ 4.7 where compound literals are suddenly temporaries (from which you cannot get a pointer) * the compound statement (also GCC extension) should ensure that the string is allocated on the stack with automatic lifetime --- src/parser.cpp | 4 ++-- src/sciteco.h | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index cb1f577..66880e3 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -322,7 +322,7 @@ StateCtlE: break; default: set(StateStart); - return g_strdup((gchar []){CTL_KEY('E'), chr, '\0'}); + return g_strdup(CHR2STR(CTL_KEY('E'), chr)); } return NULL; @@ -343,7 +343,7 @@ StateCtlEU: undo.push_obj(qregspec_machine) = NULL; set(StateStart); - return g_strdup(CHR2STR(reg->get_integer())); + return g_strdup(CHR2STR((gchar)reg->get_integer())); StateCtlEQ: reg = qregspec_machine->input(chr); diff --git a/src/sciteco.h b/src/sciteco.h index 84c9775..a1e2d4b 100644 --- a/src/sciteco.h +++ b/src/sciteco.h @@ -63,7 +63,12 @@ extern sig_atomic_t sigint_occurred; #define IS_SUCCESS(X) ((X) < 0) #define IS_FAILURE(X) (!IS_SUCCESS(X)) -#define CHR2STR(X) ((gchar []){X, '\0'}) +/* + * NOTE: compound literals are temporaries beginning with + * g++ 4.7 + */ +#define CHR2STR(X, ...) \ + ({gchar str[] = {(X), ##__VA_ARGS__, '\0'}; str;}) namespace String { -- cgit v1.2.3