All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] lib: workaround the 'redeclared with different type' errors
@ 2017-07-19 20:05 Ramsay Jones
  2017-07-20 11:57 ` Christopher Li
  0 siblings, 1 reply; 2+ messages in thread
From: Ramsay Jones @ 2017-07-19 20:05 UTC (permalink / raw)
  To: Christopher Li; +Cc: Luc Van Oostenryck, Sparse Mailing-list


The 'selfcheck' make target issues sparse errors for function symbols
'error_die' and 'die', like so:

       CHECK    lib.c
  lib.c:194:6: error: symbol 'error_die' redeclared with different type \
	(originally declared at lib.h:98) - different modifiers
  lib.c:203:6: error: symbol 'die' redeclared with different type \
	(originally declared at lib.h:94) - different modifiers

This is caused by the 'noreturn' attribute being treated similar to a
type qualifier and insisting that, not only the declaration and the
definition of the function have the 'noreturn', but that they have the
attribute in the same position.

In order to suppress the error, move the attribute(s) to the beginning
of the declaration, in the header file, and add an 'noreturn' attribute
at the beginning of the definition (in lib.c).

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---

Hi Chris,

I meant to send this yesterday, but I got busy with something else. :(
This is the 'workaround' that I have used on git to suppress these
errors (except for the regex example, which is in _imported_ code).
As I said, this also happens with the 'pure' attribute.

ATB,
Ramsay Jones

 lib.c | 2 ++
 lib.h | 9 +++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib.c b/lib.c
index ce66a81..73e9a2f 100644
--- a/lib.c
+++ b/lib.c
@@ -191,6 +191,7 @@ void expression_error(struct expression *expr, const char *fmt, ...)
 	expr->ctype = &bad_ctype;
 }
 
+NORETURN_ATTR
 void error_die(struct position pos, const char * fmt, ...)
 {
 	va_list args;
@@ -200,6 +201,7 @@ void error_die(struct position pos, const char * fmt, ...)
 	exit(1);
 }
 
+NORETURN_ATTR
 void die(const char *fmt, ...)
 {
 	va_list args;
diff --git a/lib.h b/lib.h
index c90e0e3..307ccae 100644
--- a/lib.h
+++ b/lib.h
@@ -91,11 +91,16 @@ struct token *expect(struct token *, int, const char *);
 #define NORETURN_ATTR
 #define SENTINEL_ATTR
 #endif
-extern void die(const char *, ...) FORMAT_ATTR(1) NORETURN_ATTR;
+
+FORMAT_ATTR(1) NORETURN_ATTR
+extern void die(const char *, ...);
+
+FORMAT_ATTR(2) NORETURN_ATTR
+extern void error_die(struct position, const char *, ...);
+
 extern void info(struct position, const char *, ...) FORMAT_ATTR(2);
 extern void warning(struct position, const char *, ...) FORMAT_ATTR(2);
 extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2);
-extern void error_die(struct position, const char *, ...) FORMAT_ATTR(2) NORETURN_ATTR;
 extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2);
 
 #define	ERROR_CURR_PHASE	(1 << 0)
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/2] lib: workaround the 'redeclared with different type' errors
  2017-07-19 20:05 [PATCH 1/2] lib: workaround the 'redeclared with different type' errors Ramsay Jones
@ 2017-07-20 11:57 ` Christopher Li
  0 siblings, 0 replies; 2+ messages in thread
From: Christopher Li @ 2017-07-20 11:57 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: Luc Van Oostenryck, Sparse Mailing-list

On Wed, Jul 19, 2017 at 4:05 PM, Ramsay Jones
<ramsay@ramsayjones.plus.com> wrote:
>
> The 'selfcheck' make target issues sparse errors for function symbols
> 'error_die' and 'die', like so:
>
>        CHECK    lib.c
>   lib.c:194:6: error: symbol 'error_die' redeclared with different type \
>         (originally declared at lib.h:98) - different modifiers
>   lib.c:203:6: error: symbol 'die' redeclared with different type \
>         (originally declared at lib.h:94) - different modifiers
>
> This is caused by the 'noreturn' attribute being treated similar to a
> type qualifier and insisting that, not only the declaration and the
> definition of the function have the 'noreturn', but that they have the
> attribute in the same position.
>
> In order to suppress the error, move the attribute(s) to the beginning
> of the declaration, in the header file, and add an 'noreturn' attribute
> at the beginning of the definition (in lib.c).
>
> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>

Applied to sparse-next.

Chris

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-20 11:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-19 20:05 [PATCH 1/2] lib: workaround the 'redeclared with different type' errors Ramsay Jones
2017-07-20 11:57 ` Christopher Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.