mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-26 13:02:07 +00:00
Use standard attribute syntax instead of IBM __attribute__
Move format attrs to proper standard location For some reason, GCC 13 is more lax than earlier versions...
This commit is contained in:
@@ -62,7 +62,7 @@ void processWarningFlag(char const *flag);
|
||||
* Used to warn the user about problems that don't prevent the generation of
|
||||
* valid code.
|
||||
*/
|
||||
void warning(WarningID id, char const *fmt, ...) format_(printf, 2, 3);
|
||||
[[gnu::format(printf, 2, 3)]] void warning(WarningID id, char const *fmt, ...);
|
||||
|
||||
/*
|
||||
* Used for errors that compromise the whole assembly process by affecting the
|
||||
@@ -71,7 +71,7 @@ void warning(WarningID id, char const *fmt, ...) format_(printf, 2, 3);
|
||||
* It is also used when the assembler goes into an invalid state (for example,
|
||||
* when it fails to allocate memory).
|
||||
*/
|
||||
[[noreturn]] void fatalerror(char const *fmt, ...) format_(printf, 1, 2);
|
||||
[[gnu::format(printf, 1, 2), noreturn]] void fatalerror(char const *fmt, ...);
|
||||
|
||||
/*
|
||||
* Used for errors that make it impossible to assemble correctly, but don't
|
||||
@@ -79,6 +79,6 @@ void warning(WarningID id, char const *fmt, ...) format_(printf, 2, 3);
|
||||
* get a list of all errors at the end, making it easier to fix all of them at
|
||||
* once.
|
||||
*/
|
||||
void error(char const *fmt, ...) format_(printf, 1, 2);
|
||||
[[gnu::format(printf, 1, 2)]] void error(char const *fmt, ...);
|
||||
|
||||
#endif // WARNING_H
|
||||
|
||||
@@ -3,16 +3,15 @@
|
||||
#ifndef RGBDS_ERROR_H
|
||||
#define RGBDS_ERROR_H
|
||||
|
||||
#include "helpers.hpp"
|
||||
#include "platform.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
void warn(char const *fmt...) format_(printf, 1, 2);
|
||||
void warnx(char const *fmt, ...) format_(printf, 1, 2);
|
||||
[[gnu::format(printf, 1, 2)]] void warn(char const *fmt...);
|
||||
[[gnu::format(printf, 1, 2)]] void warnx(char const *fmt, ...);
|
||||
|
||||
[[noreturn]] void err(char const *fmt, ...) format_(printf, 1, 2);
|
||||
[[noreturn]] void errx(char const *fmt, ...) format_(printf, 1, 2);
|
||||
[[gnu::format(printf, 1, 2), noreturn]] void err(char const *fmt, ...);
|
||||
[[gnu::format(printf, 1, 2), noreturn]] void errx(char const *fmt, ...);
|
||||
}
|
||||
|
||||
#endif // RGBDS_ERROR_H
|
||||
|
||||
@@ -58,7 +58,7 @@ struct Options {
|
||||
static constexpr uint8_t VERB_DEBUG = 4; // Internals are logged
|
||||
static constexpr uint8_t VERB_UNMAPPED = 5; // Unused so far
|
||||
static constexpr uint8_t VERB_VVVVVV = 6; // What, can't I have a little fun?
|
||||
format_(printf, 3, 4) void verbosePrint(uint8_t level, char const *fmt, ...) const;
|
||||
[[gnu::format(printf, 3, 4)]] void verbosePrint(uint8_t level, char const *fmt, ...) const;
|
||||
|
||||
mutable bool hasTransparentPixels = false;
|
||||
uint8_t maxOpaqueColors() const { return nbColorsPerPal - hasTransparentPixels; }
|
||||
@@ -73,11 +73,11 @@ extern Options options;
|
||||
/*
|
||||
* Prints a warning, and does not change the error count
|
||||
*/
|
||||
void warning(char const *fmt, ...) format_(printf, 1, 2);
|
||||
[[gnu::format(printf, 1, 2)]] void warning(char const *fmt, ...);
|
||||
/*
|
||||
* Prints an error, and increments the error count
|
||||
*/
|
||||
void error(char const *fmt, ...) format_(printf, 1, 2);
|
||||
[[gnu::format(printf, 1, 2)]] void error(char const *fmt, ...);
|
||||
/*
|
||||
* Prints an error, and increments the error count
|
||||
* Does not take format arguments so `format_` and `-Wformat-security` won't complain about
|
||||
@@ -87,7 +87,7 @@ void errorMessage(char const *msg);
|
||||
/*
|
||||
* Prints a fatal error, increments the error count, and gives up
|
||||
*/
|
||||
[[noreturn]] void fatal(char const *fmt, ...) format_(printf, 1, 2);
|
||||
[[gnu::format(printf, 1, 2), noreturn]] void fatal(char const *fmt, ...);
|
||||
|
||||
struct Palette {
|
||||
// An array of 4 GBC-native (RGB555) colors
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
|
||||
// Ideally, we'd use `__has_attribute` and `__has_builtin`, but these were only introduced in GCC 9
|
||||
#ifdef __GNUC__ // GCC or compatible
|
||||
#define format_(archetype, str_index, first_arg) \
|
||||
__attribute__((format(archetype, str_index, first_arg)))
|
||||
#define attr_(...) __attribute__((__VA_ARGS__))
|
||||
// In release builds, define "unreachable" as such, but trap in debug builds
|
||||
#ifdef NDEBUG
|
||||
#define unreachable_ __builtin_unreachable
|
||||
@@ -15,9 +12,6 @@
|
||||
#define unreachable_ __builtin_trap
|
||||
#endif
|
||||
#else
|
||||
// Unsupported, but no need to throw a fit
|
||||
#define format_(archetype, str_index, first_arg)
|
||||
#define attr_(...)
|
||||
// This seems to generate similar code to __builtin_unreachable, despite different semantics
|
||||
// Note that executing this is undefined behavior (declared [[noreturn]], but does return)
|
||||
[[noreturn]] static inline void unreachable_() {
|
||||
|
||||
@@ -59,10 +59,11 @@ struct FileStackNode {
|
||||
std::string const &dump(uint32_t curLineNo) const;
|
||||
};
|
||||
|
||||
void warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||
format_(printf, 3, 4);
|
||||
void error(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) format_(printf, 3, 4);
|
||||
[[noreturn]] void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||
format_(printf, 3, 4);
|
||||
[[gnu::format(printf, 3, 4)]] void
|
||||
warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
|
||||
[[gnu::format(printf, 3, 4)]] void
|
||||
error(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
|
||||
[[gnu::format(printf, 3, 4), noreturn]] void
|
||||
fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
|
||||
|
||||
#endif // RGBDS_LINK_MAIN_H
|
||||
|
||||
Reference in New Issue
Block a user