GCC Wikia
Advertisement

このページを編集する際は,編集に関する方針に従ってください.[]

概要[]

引数[]

  • cpp_reader * pfile
  • int level
  • const char *msgid
  • ...

実装[]

134 /* Print an error at the location of the previously lexed token.  */
135 void
136 cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
137 {
138   source_location src_loc;
139   va_list ap;
140   
141   va_start (ap, msgid);
142 


  • pfileのコールバック関数に任せる

143   if (CPP_OPTION (pfile, client_diagnostic))
144     pfile->cb.error (pfile, level, _(msgid), &ap);


145   else
146     {

  • エラーの一個前の場所(ファイル、行、列)を調べる

147       if (CPP_OPTION (pfile, traditional))
148         {
149           if (pfile->state.in_directive)
150             src_loc = pfile->directive_line;
151           else
152             src_loc = pfile->line_table->highest_line;
153         }
154       else
155         {
156           src_loc = pfile->cur_token[-1].src_loc;
157         }
158 

  • よく見る以下のようなメッセージの表示
    • どういった経緯でここまで来たのか
    • エラー、警告の原因
In file included from b.h:8,
                 from a.c:1:
d.h:1:9: error: #include expects "FILENAME" or <FILENAME>

159       if (_cpp_begin_message (pfile, level, src_loc, 0))
160         v_message (msgid, ap);
161     }
162 
163   va_end (ap);
164 }



リンク元

Advertisement