Changeset 2103a51


Ignore:
Timestamp:
Mar 1, 2018, 2:42:45 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
babeeda
Parents:
6bc76537
Message:

Fix SemanticWarningImpl?

Location:
src/Common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Common/SemanticError.cc

    r6bc76537 r2103a51  
    5050}
    5151
    52 void SemanticWarningImpl( CodeLocation location, std::string msg ) {
     52namespace {
     53        // convert format string and arguments into a single string
     54        std::string fmtToString(const char * fmt, va_list ap) {
     55                int size = 128;
     56                while ( true ) {
     57                        char buf[size];
     58                        va_list args;
     59                        va_copy( args, ap );
     60                        int n = vsnprintf(&buf[0], size, fmt, args);
     61                        va_end( args );
     62                        if ( n < size && n >= 0 ) return buf;
     63                        size *= 2;
     64                }
     65                assert( false );
     66        }
     67}
     68
     69void SemanticWarningImpl( CodeLocation location, Warning, const char * const fmt, ... ) {
     70        va_list args;
     71        va_start(args, fmt);
     72        std::string msg = fmtToString( fmt, args );
     73        va_end(args);
    5374        std::cerr << ErrorHelpers::bold() << location << ErrorHelpers::warning_str() << ErrorHelpers::reset_font() << msg << std::endl;
    5475}
  • src/Common/SemanticError.h

    r6bc76537 r2103a51  
    4949);
    5050
    51 #define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[id], __VA_ARGS__)
     51#define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id], __VA_ARGS__)
    5252
    5353void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
Note: See TracChangeset for help on using the changeset viewer.