Studying note of GCC-3.4.6 source (25 cont1)

c_common_handle_option (continue)

 

401     case OPT_Wbad_function_cast:

402        warn_bad_function_cast = value;

403        break;

404 

405      case OPT_Wcast_qual:

406        warn_cast_qual = value;

407        break;

408 

409      case OPT_Wchar_subscripts:

410        warn_char_subscripts = value;

411        break;

412 

413      case OPT_Wcomment:

414      case OPT_Wcomments:

415        cpp_opts->warn_comments = value;

416        break;

417 

418      case OPT_Wconversion:

419        warn_conversion = value;

420        break;

421 

422      case OPT_Wctor_dtor_privacy:

423        warn_ctor_dtor_privacy = value;

424        break;

425 

426      case OPT_Wdeclaration_after_statement:

427        warn_declaration_after_statement = value;

428        break;

429 

430      case OPT_Wdeprecated:

431        warn_deprecated = value;

432        cpp_opts->warn_deprecated = value;

433        break;

434 

435      case OPT_Wdiv_by_zero:

436        warn_div_by_zero = value;

437        break;

438 

439      case OPT_Weffc__:

440        warn_ecpp = value;

441        break;

442 

443      case OPT_Wendif_labels:

444        cpp_opts->warn_endif_labels = value;

445        break;

446 

447      case OPT_Werror:

448        cpp_opts->warnings_are_errors = value;

449        break;

450 

451      case OPT_Werror_implicit_function_declaration:

452        mesg_implicit_function_declaration = 2;

453        break;

454 

455      case OPT_Wfloat_equal:

456        warn_float_equal = value;

457        break;

458 

459      case OPT_Wformat:

460        set_Wformat (value);

461        break;

462 

463      case OPT_Wformat_:

464        set_Wformat (atoi (arg));

465        break;

466 

467      case OPT_Wformat_extra_args:

468        warn_format_extra_args = value;

469        break;

470 

471      case OPT_Wformat_nonliteral:

472        warn_format_nonliteral = value;

473        break;

474 

475      case OPT_Wformat_security:

476        warn_format_security = value;

477        break;

478 

479      case OPT_Wformat_y2k:

480        warn_format_y2k = value;

481        break;

482 

483      case OPT_Wformat_zero_length:

484        warn_format_zero_length = value;

485        break;

486 

487      case OPT_Winit_self:

488        warn_init_self = value;

489        break;

490 

491      case OPT_Wimplicit:

492        set_Wimplicit (value);

493        break;

494 

495      case OPT_Wimplicit_function_declaration:

496        mesg_implicit_function_declaration = value;

497        break;

498 

499      case OPT_Wimplicit_int:

500        warn_implicit_int = value;

501        break;

502 

503      case OPT_Wimport:

504        /* Silently ignore for now.  */

505        break;

506 

507      case OPT_Winvalid_offsetof:

508        warn_invalid_offsetof = value;

509        break;

510 

511      case OPT_Winvalid_pch:

512        cpp_opts->warn_invalid_pch = value;

513        break;

514 

515      case OPT_Wlong_long:

516        warn_long_long = value;

517        break;

518 

519      case OPT_Wmain:

520        if (value)

521          warn_main = 1;

522        else

523          warn_main = -1;

524        break;

525 

526      case OPT_Wmissing_braces:

527        warn_missing_braces = value;

528        break;

529 

530      case OPT_Wmissing_declarations:

531        warn_missing_declarations = value;

532        break;

533 

534      case OPT_Wmissing_format_attribute:

535        warn_missing_format_attribute = value;

536        break;

537 

538      case OPT_Wmissing_prototypes:

539        warn_missing_prototypes = value;

540        break;

541 

542      case OPT_Wmultichar:

543        cpp_opts->warn_multichar = value;

544        break;

545 

546      case OPT_Wnested_externs:

547        warn_nested_externs = value;

548        break;

549 

550      case OPT_Wnon_template_friend:

551        warn_nontemplate_friend = value;

552        break;

553 

554      case OPT_Wnon_virtual_dtor:

555        warn_nonvdtor = value;

556        break;

557 

558      case OPT_Wnonnull:

559        warn_nonnull = value;

560        break;

561 

562      case OPT_Wold_style_definition:

563        warn_old_style_definition = value;

564        break;

565 

566      case OPT_Wold_style_cast:

567        warn_old_style_cast = value;

568        break;

569 

570      case OPT_Woverloaded_virtual:

571        warn_overloaded_virtual = value;

572        break;

573 

574      case OPT_Wparentheses:

575        warn_parentheses = value;

576        break;

577 

578      case OPT_Wpmf_conversions:

579        warn_pmf2ptr = value;

580        break;

581 

582      case OPT_Wpointer_arith:

583        warn_pointer_arith = value;

584        break;

585 

586      case OPT_Wprotocol:

587        warn_protocol = value;

588        break;

589 

590      case OPT_Wselector:

591        warn_selector = value;

592        break;

593 

594      case OPT_Wredundant_decls:

595        warn_redundant_decls = value;

596        break;

597 

598      case OPT_Wreorder:

599        warn_reorder = value;

600        break;

601 

602      case OPT_Wreturn_type:

603        warn_return_type = value;

604        break;

605 

606      case OPT_Wsequence_point:

607        warn_sequence_point = value;

608        break;

609 

610      case OPT_Wsign_compare:

611        warn_sign_compare = value;

612        break;

613 

614      case OPT_Wsign_promo:

615        warn_sign_promo = value;

616        break;

617 

618      case OPT_Wstrict_prototypes:

619        warn_strict_prototypes = value;

620        break;

621 

622      case OPT_Wsynth:

623        warn_synth = value;

624        break;

625 

626      case OPT_Wsystem_headers:

627        cpp_opts->warn_system_headers = value;

628        break;

629 

630      case OPT_Wtraditional:

631        warn_traditional = value;

632        cpp_opts->warn_traditional = value;

633        break;

634 

635      case OPT_Wtrigraphs:

636        cpp_opts->warn_trigraphs = value;

637        break;

638 

639      case OPT_Wundeclared_selector:

640        warn_undeclared_selector = value;

641        break;

642 

643      case OPT_Wundef:

644        cpp_opts->warn_undef = value;

645        break;

646 

647      case OPT_Wunknown_pragmas:

648        /* Set to greater than 1, so that even unknown pragmas in

649          system headers will be warned about.  */

650        warn_unknown_pragmas = value * 2;

651        break;

652 

653      case OPT_Wunused_macros:

654        warn_unused_macros = value;

655        break;

 

Above, the details about the variables are shown in following.

warn_bad_function_cast (C, -Wbad-function-cast) if nonzero, issues a warning whenever a function is cast to a non-matching type. For example, the following will cause a warning to be issued on the function call:

int glim() {   

return(88);

}

. . .

char *cp;

cp = (char *)glim();

warn_cast_qual (C, C++, ObjC, -Wcast-qual) if nonzero, issues a warning whenever a function call removes a qualifier. For example, the following removes the const qualifier:

const char *conchp;

char *chp;

. . .

chp = (char *)conchp;

warn_conversion (C, C++, ObjC, -Wconversion) if nonzero, issues a warning if a prototype causes a type conversion other than the one that would occur if the conversion were made without the prototype. This includes converting between real and integer data types, signed and unsigned values, as well as changing the width of the value. Warnings are issued only for implicit conversions (coercion), but not for specific casts. For example, the first of the following assignment statements will issue a warning but the second will not:

unsigned int recp;

recp = -1;

recp = (unsigned int)-1;

warn_ctor_dtor_privacy (C++, -Wctor-dtor-privacy, also set by -Wall) if nonzero, issues a warning if a class appears to be unusable because it has only private constructors or destructors, no friends, and no public or static members.

warn_deprecated (C++, -Wdeprecated) if nonzero, means complain about deprecated features (default value is 1).

warn_div_by_zero (-Wdiv-by-zero) if nonzero, warns about compile-time division by zero. There is no warning for floating point division by zero (default value is 1).

warn_ecpp (C++, -Weffc++) if nonzero, issues warnings for violations of some of the style guidelines from the book Effective C++ by Scott Myers. The standard library headers do not follow these guidelines, so you will also get warnings issued from them.

warn_float_equal (-Wfloat-equal), if two floating point numbers are compared for equality, a warning is issued because this is often an error in the logic of the program. It is the nature of floating point arithmetic that calculated real numbers are rarely equal to one another. This means that comparison for exact equality on two real numbers can fail even if the numbers are close enough together for the logic of your program to treat them as if they were identical. The following is a technique for comparing floating point numbers if your program considers equality being within 0.00001 of one another:

double delta = 0.00001;

. . .

if((val1 > val2-delta) && (val1 < val2+delta) {

/* val1 and val2 are considered equal */

}

warn_init_self (-Winit-self) if nonzero, warns about uninitialized variable when it is initialized with itself. For example: int i = i;

warn_invalid_offsetof (-Winvalid-offsetof) if nonzero, warns about invalid uses of offsetof (the default value is 1).

warn_long_long (C, C++, ObjC, -Wlong-long) if nonzero, warns about usage of long long when `-pedantic' is used (the default value is 1).

warn_missing_declarations (C, -Wmissing-declarations) if nonzero, warns for any global function definition without separate previous declacration.

warn_missing_format_attribute (C, C++, ObjC, -Wmissing-format-attribute) if nonzero, issues warnings which might be candidates for the format attribute. It should be noted that the warnings are issued for possible noreturn candidates. This option has no effect unless the option -Wformat or -Wall has also been specified.

warn_missing_prototypes (C, -Wmissing-prototype) if nonzero, warn for any global function definition without separate previous prototype declaration.

warn_nested_externs (C, -Wnested-externs) if nonzero, issues a warning for an extern declaration inside a function.

warn_old_style_definition (-Wold-style-definition) if nonzero, warns about old-style parameter declaration.

warn_old_style_cast (C++, -Wold-style-cast) if nonzero, issues a warning when a traditional style (C language style) cast is used instead of one of the new forms from the C++ standard with one of the casting operators static_cast, const_cast, or reinterpret_cast. For example:

class A { ... };

class B: public A { ... };

. . .

A* a = new A();

B* b = a; //implicit conversion

A* a2 = static_cast<A*>(b); //reversing an implicit conversion

warn_overloaded_virtual (C++, -Woverloaded-virtual) if nonzero, issues a warning when a function declaration hides a virtual function declared in a base class. In the following example the function fn() in class A is hidden:

class A {

virtual void fn();

};

class B: public A {

void fn(int);

};

warn_pmf2ptr (C++, -Wpmf-conversions) if nonzero, warns when we convert a pointer to member function into a pointer to (void or function) (the default value is 1).

warn_pointer_arith (C, C++, ObjC, -Wpointer-arith) if nonzero, issues a warning for anything that depends on the size of a function type or of void. For the sake of pointer arithmetic, the GCC default size for these items is 1.

warn_redundant_decls (C, C++, ObjC, -Wredundant-decls) if nonzero, warns about multiple (redundant) decls for the same single variable or function.

warn_sign_promo (C++, -Wsign-prom) if nonzero, issues a warning when overloading from an unsigned (or enumerated type) data type to a signed data type of the same size. The standard specifies this type of conversion, but it could cause loss of data.

warn_synth (C++, -Wsynth) if nonzero, issues a warning when operator synthesis is different from cfront. In the following example GCC will synthesize the operator A& operator = (const A&); where cfront employs the user-defined default operator =.

class A {

operator int();

A& operator = (int);

};

main() {

A a1;

A a2;

a1 = a2;

}

warn_traditional (C, -Wtraditional) if nonzero, issues warnings for standard C constructs that may have a different meaning, or did not exist, in traditional C. Some of these are ambiguous or problematic constructs that should be avoided.

Ÿ        Macro parameters that appear within string literals in the macro body. In traditional C macro replacement takes place within string literals, but does not in ISO C.

Ÿ        In traditional C, some preprocessor directives did not exist. Traditional preprocessors would only consider a line to be a directive if the ‘#’ appeared in column 1 on the line. Therefore ‘-Wtraditional’ warns about directives that traditional C understands but would ignore because the ‘#’ does not appear as the first character on the line. It also suggests you hide directives like ‘#pragma’ not understood by traditional C by indenting them. Some traditional implementations would not recognize ‘#elif’, so it suggests avoiding it altogether.

Ÿ        A function-like macro that appears without arguments.

Ÿ        The unary plus operator.

Ÿ        The ‘U’ integer constant suffix, or the ‘F’ or ‘L’ floating point constant suffixes. (Traditional C does support the ‘L’ suffix on integer constants.) Note, these suffixes appear in macros defined in the system headers of most modern systems, e.g. the ‘_MIN’/’_MAX’ macros in <limits.h>. Use of these macros in user code might normally lead to spurious warnings, however GCC’s integrated preprocessor has enough context to avoid warning in these cases.

Ÿ        A function declared external in one block and then used after the end of the block.

Ÿ        A switch statement has an operand of type long.

Ÿ        A non-static function declaration follows a static one. This construct is not accepted by some traditional C compilers.

Ÿ        The ISO type of an integer constant has a different width or signedness from its traditional type. This warning is only issued if the base of the constant is ten. I.e. hexadecimal or octal values, which typically represent bit patterns, are not warned about.

Ÿ        Usage of ISO string concatenation is detected.

Ÿ        Initialization of automatic aggregates.

Ÿ        Identifier conflicts with labels. Traditional C lacks a separate namespace for labels.

Ÿ        Initialization of unions. If the initializer is zero, the warning is omitted. This is done under the assumption that the zero initializer in user code appears conditioned on e.g. __STDC__ to avoid missing initializer warnings and relies on default initialization to zero in the traditional C case.

Ÿ        Conversions by prototypes between fixed/floating point values and vice versa. The absence of these prototypes when compiling with traditional C would cause serious problems. This is a subset of the possible conversion warnings, for the full set use ‘-Wtraditional-conversion’.

Ÿ        Use of ISO C style function definitions. This warning intentionally is not issued for prototype declarations or variadic functions because these ISO C features will appear in your code when using libiberty’s traditional C compatibility macros, PARAMS and VPARAMS. This warning is also bypassed for nested functions because that feature is already a GCC extension and thus not relevant to traditional C compatibility.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值