1
0

fix: change the behavior of printf in string op.

- add compiler hint for checking the arguments of printf.
- change the return value of printf. from std::expected to normal value. use C++ exception to indicate error.
	* the error of printf usually caused by programmer. so it can be found when testing program.
	* so i use std::logic_error to indicate this and programmer should fix this before releasing program.
- change the use of encoding convertion. for those cases that convertion must be safe, we unwrap it directly.
This commit is contained in:
2025-09-22 22:14:36 +08:00
parent 45e4031b5c
commit c85830902b
22 changed files with 240 additions and 164 deletions

View File

@ -0,0 +1,28 @@
#pragma once
#include "compiler_detector.hpp"
#include "stl_detector.hpp"
// YYC MARK:
// This code is copied from Qt project.
#if defined(YYCC_CC_GCC)
// GCC has its special attribute
#define YYCC_PRINTF_CHECK_ATTR(A, B) __attribute__((format(gnu_printf, (A), (B))))
#elif defined(YYCC_CC_CLANG)
// Clang use its own attribute
#define YYCC_PRINTF_CHECK_ATTR(A, B) __attribute__((format(printf, (A), (B))))
#else
// Other CC do not support this (like MSVC), skip it
#define YYCC_PRINTF_CHECK_ATTR(A, B)
#endif
#if defined(YYCC_STL_MSSTL)
// On Microsoft STL, we can use some mechanisms to check it.
#include "../windows/import_guard_head.hpp"
#include <sal.h>
#include "../windows/import_guard_tail.hpp"
#define YYCC_PRINTF_CHECK_FMTSTR _Printf_format_string_
#else
// Other STL do not have this.
#define YYCC_PRINTF_CHECK_FMTSTR
#endif