Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/SemanticError.cc

    ra16764a6 r244b934  
    1414//
    1515
     16#include <cstdarg>
    1617#include <cstdio>                                                                               // for fileno, stderr
    1718#include <unistd.h>                                                                             // for isatty
     
    5051}
    5152
    52 void SemanticWarningImpl( CodeLocation location, std::string msg ) {
     53namespace {
     54        // convert format string and arguments into a single string
     55        std::string fmtToString(const char * fmt, va_list ap) {
     56                int size = 128;
     57                while ( true ) {
     58                        char buf[size];
     59                        va_list args;
     60                        va_copy( args, ap );
     61                        int n = vsnprintf(&buf[0], size, fmt, args);
     62                        va_end( args );
     63                        if ( n < size && n >= 0 ) return buf;
     64                        size *= 2;
     65                }
     66                assert( false );
     67        }
     68}
     69
     70void SemanticWarningImpl( CodeLocation location, Warning, const char * const fmt, ... ) {
     71        va_list args;
     72        va_start(args, fmt);
     73        std::string msg = fmtToString( fmt, args );
     74        va_end(args);
    5375        std::cerr << ErrorHelpers::bold() << location << ErrorHelpers::warning_str() << ErrorHelpers::reset_font() << msg << std::endl;
    5476}
Note: See TracChangeset for help on using the changeset viewer.