Author Topic: Build messages settings and Find/Replace tool  (Read 26514 times)

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Build messages settings and Find/Replace tool
« on: August 31, 2011, 09:49:52 am »
I've got two questions for code::blocks I need help with.

1):
Normally, for code::blocks, when I click on build error messages, it jumps to the line of which the error is on. For some reason, however, this is disabled for me - what settings do I have to modify in order to re-enable it?

2):
When using the Find and/or Replace feature, I have trouble optimising the search such that it doesn't bring up false positives (I'm working with 10+ files), for example:

Say I want to replace the return variable of numerous differently name functions, such that:

bool ReturnBool()
bool SomeOtherFunction()

become:

const bool ReturnBool()
const bool SomeOtherFunction()

You would search for 'bool' and replace it with 'const bool'. But my problem is, there already exist instances of 'const bool', of which it picks up, and there are also booleans which are variables (and not function returns) - and there a lot of instances of pre-existing 'const bools', so for example:

bool ReturnBool()
const bool ReturnConstBool()
const bool ReturnConstBool(const bool IsAcceptable)
bool Toggle;

would become:

const bool ReturnBool()
const const bool ReturnConstBool()
const const bool ReturnConstBool(const const bool IsAcceptable)
const bool Toggle; //This is now read only. Which is bad.

Just to add: Whilst it would be an idea to say to manually sift through the code, there are 10+ pages of code to sift through, and this process gets extremely tedious given there are a lot of const bool returning functions. The bool to const bool is a standardising process to check for any functions not compliant - but it catches all the functions that are already compliant.

Is there any way that I could somehow:

1) Specify a 'but not' instance, so for example:
Search for all:
bool
But not:
const bool
Replace with:
const bool

2) Make it avoid replacing instances of pre-existing const bools?
3) Make it avoid variables?

I imagine this isn't likely to get an answer, but would it be worth considering implementing a 'but not' feature?
« Last Edit: August 31, 2011, 09:53:27 am by Joshua Flynn »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Build messages settings and Find/Replace tool
« Reply #1 on: August 31, 2011, 10:00:57 am »
1) we need more details here
2) you can use regular expression to help you minimize the false positives, but they don't know if a match is a function definition/declaration, variable or call to a function.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Build messages settings and Find/Replace tool
« Reply #2 on: August 31, 2011, 10:06:07 am »
1) we need more details here
2) you can use regular expression to help you minimize the false positives, but they don't know if a match is a function definition/declaration, variable or call to a function.

1) Basically, when you compile a program, if there are any warnings or errors, they are reported in the build messages/build log. Normally, when you click (or double-click) on the messages, it takes you to the line in the code where the error occurred (which is extremely useful in a large code base), but for some reason, it no longer jumps to the specific lines. So I am wondering how I would re-enable this, as it somehow got disabled.

2) What are valid regular expressions, and how do I use them? Anything that helps reduce false positives is appreciated.

Thank you.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Build messages settings and Find/Replace tool
« Reply #3 on: August 31, 2011, 10:23:36 am »
1) we need more details here
2) you can use regular expression to help you minimize the false positives, but they don't know if a match is a function definition/declaration, variable or call to a function.

1) Basically, when you compile a program, if there are any warnings or errors, they are reported in the build messages/build log. Normally, when you click (or double-click) on the messages, it takes you to the line in the code where the error occurred (which is extremely useful in a large code base), but for some reason, it no longer jumps to the specific lines. So I am wondering how I would re-enable this, as it somehow got disabled.

Can you post a snippet of the content of the "Build log" and the "Build messages" with an error messages that does not work ?

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Build messages settings and Find/Replace tool
« Reply #4 on: August 31, 2011, 10:33:35 am »
Can you post a snippet of the content of the "Build log" and the "Build messages" with an error messages that does not work ?

Sure:

D\FileProcModular.h|335|error: 'const bool FileProcModular::operator=(long unsigned int)' cannot be overloaded|



Normally if I click on it, it should take me to the file and line, but it doesn't. Some projects do and some don't. So I think there might be a setting issue?

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Build messages settings and Find/Replace tool
« Reply #5 on: August 31, 2011, 10:57:27 am »
Another couple of questions: How do I make it so the build messages either retains the warning messages (on a successful compile) or quits when it gets an warning?

Is it possible to disable specific warning messages? And if so, how?

Sorry for the questions.

zabzonk

  • Guest
Re: Build messages settings and Find/Replace tool
« Reply #6 on: August 31, 2011, 11:42:09 am »
Not to do with your two main questions, but just to note that returning const values of any sort is kind of a waste of time in C++.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Build messages settings and Find/Replace tool
« Reply #7 on: August 31, 2011, 12:13:52 pm »
Another couple of questions: How do I make it so the build messages either retains the warning messages (on a successful compile) or quits when it gets an warning?

Is it possible to disable specific warning messages? And if so, how?
Yes, but this depends on the compiler, for gcc check the various -W options.
Then you set the options in Project->build options -> target -> compiler -> other (if there is no such option in the main options)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Build messages settings and Find/Replace tool
« Reply #8 on: August 31, 2011, 12:41:35 pm »
Please read carefully:
Can you post a snippet of the content of the "Build log" and the "Build messages" with an error messages that does not work ?

Just copy and paste, please do not post a screenshot, if it is not absolutely necessary.

Offline Freem

  • Almost regular
  • **
  • Posts: 219
Re: Build messages settings and Find/Replace tool
« Reply #9 on: August 31, 2011, 02:02:31 pm »
2) What are valid regular expressions, and how do I use them? Anything that helps reduce false positives is appreciated.
http://en.wikipedia.org/wiki/Regular_expression

There is a plugin in C::B to test your regex, too. (regular expressions testbed or something like that).
But I don't know exactly if C::B only use POSIX, or support PERL, or a mix between them, or a "POSIX-LITE".

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Build messages settings and Find/Replace tool
« Reply #10 on: August 31, 2011, 02:06:38 pm »
C::B supports, what wxRegEx supports.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Build messages settings and Find/Replace tool
« Reply #11 on: August 31, 2011, 05:31:06 pm »
Sorry for the delay in reply.

Not to do with your two main questions, but just to note that returning const values of any sort is kind of a waste of time in C++.

Const means read-only. Returning a bool (it was written on stack overflow {the website}), a user might attempt to over-write it (ReturnBool() = true), which would cause a crash (temporary variable?). It's extremely useful when passing by reference (so you know the variable being referred can't be altered). Generally good practice to make sure returning variables are read-only unless otherwise explicitly stated.

Yes, but this depends on the compiler, for gcc check the various -W options.
Then you set the options in Project->build options -> target -> compiler -> other (if there is no such option in the main options)

I think it's GCC. Is a pragma command possible?

Just copy and paste, please do not post a screenshot, if it is not absolutely necessary.

Code
D\FileProcModular.h|21|warning: multi-character character constant|
D\FileProcModular.h|22|warning: multi-character character constant|
D\FileProcModular.h|23|warning: multi-character character constant|
D\FileProcModular.h|25|warning: multi-character character constant|
D\FileProcModular.h|26|warning: multi-character character constant|
D\FileProcModular.h|27|warning: multi-character character constant|
D\FileProcModular.h|29|warning: multi-character character constant|
D\FileProcModular.h|30|warning: multi-character character constant|
D\FileProcModular.h|31|warning: multi-character character constant|
D\FileProcModular.h|33|warning: multi-character character constant|
D\FileProcModular.h|34|warning: multi-character character constant|
D\FileProcModular.h|35|warning: multi-character character constant|
D\CharList.h||In member function 'const bool CharList::CopyBetweenStrings(const char*, const char*, const char*, bool)':|
D\CharList.h|504|warning: declaration of 'End' shadows a member of 'this'|
D\CharList.h|504|warning: declaration of 'Start' shadows a member of 'this'|
D\CharList.h|512|warning: unused variable 'C_Ptr_End'|
||=== Build finished: 0 errors, 15 warnings ===|

There is a plugin in C::B to test your regex, too. (regular expressions testbed or something like that).
But I don't know exactly if C::B only use POSIX, or support PERL, or a mix between them, or a "POSIX-LITE".

Can you tell me valid regular expressions?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Build messages settings and Find/Replace tool
« Reply #12 on: August 31, 2011, 05:44:54 pm »
bool myFunc() { return true; }

if (myFunc()=true) <-- this cannot crash, because the temporary is valid/alive until the closing brace!
const bool myFunc() is total waste of typing and then reading, keep in mind that reading code takes 90% of the time!

Some info const by a real guru: http://www.gotw.ca/gotw/081.htm

Please try the regular expression testbed plugin (it is in the plugins menu and you need the contrib plugins installed).
Keep in mind that using regular expressions require thinking and creativity, they are no silver bullet!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Build messages settings and Find/Replace tool
« Reply #13 on: August 31, 2011, 06:27:40 pm »
bool myFunc() { return true; }

if (myFunc()=true) <-- this cannot crash, because the temporary is valid/alive until the closing brace!
const bool myFunc() is total waste of typing and then reading, keep in mind that reading code takes 90% of the time!

Some info const by a real guru: http://www.gotw.ca/gotw/081.htm

Consider:
Code
class Test
{
    public:
    int A;
    Test(){A = 0;}
};

const Test &ReturnTest1(){Test N; return N;}
const Test ReturnTest2(){Test N; return N;}
Test &ReturnTest3(){Test N; return N;}
Test ReturnTest4(){Test N; return N;}


int main(int ArgC, char *ArgV[])
{
    ReturnTest1().A = 1; //Produces an access violation as it's const
    ReturnTest2().A = 1; //Produces an access violation as it's const
    ReturnTest3().A = 1; //No violation (as a reference this could be bad)
    ReturnTest4().A = 1; //No violation (as a copy this would be pointless)
    return 0;
}

Even though C++ doesn't enforce const bools/ints/floats/chars, it does with classes, and it is a good habit to code consistently across the board, given that is the intention. Const at the start right away tells it's returning read-only (and thus shouldn't be modified anyway), and by making it the default (even if seemingly redundant), it becomes a habit that is applied to other classes.

It's a matter of indicating intentions. If I put const float (instead of const float&) by accident, anyone correcting that, knows the reference need to be read-only. If I put just float, a person could correct to float&, and thus it would be valid for the user to internally modify it. Not good.

Please try the regular expression testbed plugin (it is in the plugins menu and you need the contrib plugins installed).
Keep in mind that using regular expressions require thinking and creativity, they are no silver bullet!

Is there a manual I could read on the topic? I don't think I have that plugin installed.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Build messages settings and Find/Replace tool
« Reply #14 on: August 31, 2011, 06:50:13 pm »
Probably this: http://wiki.codeblocks.org/index.php?title=Code::Blocks_Plugins
but there is no page for the regex testbed plugin, but it is pretty straight forward, just open the dialog :)

If you don't have you probably don't have the contrib plugins installed.
And as you've not mentioned anything about your computer: os, c::b version, compiler (not important here, but it is good to know!);
we can't tell you how to installed them.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Build messages settings and Find/Replace tool
« Reply #15 on: August 31, 2011, 07:12:54 pm »
Probably this: http://wiki.codeblocks.org/index.php?title=Code::Blocks_Plugins
but there is no page for the regex testbed plugin, but it is pretty straight forward, just open the dialog :)

If you don't have you probably don't have the contrib plugins installed.
And as you've not mentioned anything about your computer: os, c::b version, compiler (not important here, but it is good to know!);
we can't tell you how to installed them.

Code:blocks version 10.05, windows vista, gcc (I believe).

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Build messages settings and Find/Replace tool
« Reply #16 on: August 31, 2011, 07:20:57 pm »
Last try, after that I give up:
Please read carefully:
Can you post a snippet of the content of the "Build log" and the "Build messages" with an error messages that does not work ?

Just copy and paste, please do not post a screenshot, if it is not absolutely necessary.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Build messages settings and Find/Replace tool
« Reply #17 on: August 31, 2011, 07:41:40 pm »
Code:blocks version 10.05, windows vista, gcc (I believe).
Reinstall and make sure the checkbox for contrib plugins is checked.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Build messages settings and Find/Replace tool
« Reply #18 on: August 31, 2011, 08:24:17 pm »
Last try, after that I give up:
Please read carefully:
Can you post a snippet of the content of the "Build log" and the "Build messages" with an error messages that does not work ?

Just copy and paste, please do not post a screenshot, if it is not absolutely necessary.

Build log:
Code
-------------- Build: Release in SelfBuilding ---------------

Compiling: main.cpp
In file included from C:\Users\user\Desktop\Projects\R&D\main.cpp:6:
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:21:25: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:22:24: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:23:26: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:25:23: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:26:22: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:27:24: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:29:30: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:30:29: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:31:31: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:33:30: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:34:29: warning: multi-character character constant
C:\Users\user\Desktop\Projects\R&D\FileProcModular.h:35:31: warning: multi-character character constant
In file included from C:\Users\user\Desktop\Projects\R&D\StrToken.h:9,
                 from C:\Users\user\Desktop\Projects\R&D\HTMLFileProc.h:9,
                 from C:\Users\user\Desktop\Projects\R&D\main.cpp:5:
C:\Users\user\Desktop\Projects\R&D\DataArray.h: In member function 'const bool DataArray::CopyBetweenStrings(const char*, const char*, const char*, bool)':
C:\Users\user\Desktop\Projects\R&D\DataArray.h:190: error: 'StringString' was not declared in this scope
C:\Users\user\Desktop\Projects\R&D\DataArray.h:207: warning: suggest parentheses around assignment used as truth value
C:\Users\user\Desktop\Projects\R&D\DataArray.h:207: error: expected primary-expression before ')' token
C:\Users\user\Desktop\Projects\R&D\DataArray.h:207: error: expected ';' before ')' token
Process terminated with status 1 (0 minutes, 1 seconds)
3 errors, 13 warnings

Build messages:
Code
D\FileProcModular.h|21|warning: multi-character character constant|
D\FileProcModular.h|22|warning: multi-character character constant|
D\FileProcModular.h|23|warning: multi-character character constant|
D\FileProcModular.h|25|warning: multi-character character constant|
D\FileProcModular.h|26|warning: multi-character character constant|
D\FileProcModular.h|27|warning: multi-character character constant|
D\FileProcModular.h|29|warning: multi-character character constant|
D\FileProcModular.h|30|warning: multi-character character constant|
D\FileProcModular.h|31|warning: multi-character character constant|
D\FileProcModular.h|33|warning: multi-character character constant|
D\FileProcModular.h|34|warning: multi-character character constant|
D\FileProcModular.h|35|warning: multi-character character constant|
D\DataArray.h||In member function 'const bool DataArray::CopyBetweenStrings(const char*, const char*, const char*, bool)':|
D\DataArray.h|190|error: 'StringString' was not declared in this scope|
D\DataArray.h|207|warning: suggest parentheses around assignment used as truth value|
D\DataArray.h|207|error: expected primary-expression before ')' token|
D\DataArray.h|207|error: expected ';' before ')' token|
||=== Build finished: 3 errors, 13 warnings ===|

The error messages will vary as I am working on the project. Just that being unable to jump to the specific error lines is time-consuming.

The problem applies to any warnings/errors (if this wasn't clear in the original post).
« Last Edit: August 31, 2011, 08:29:20 pm by Joshua Flynn »

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Build messages settings and Find/Replace tool
« Reply #19 on: August 31, 2011, 08:34:56 pm »
Reinstall and make sure the checkbox for contrib plugins is checked.

Reinstalled it and made sure the RegEx testbed plugin was checked. I'll try it out.

Re-install doesn't fix the goto error line thingy.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Build messages settings and Find/Replace tool
« Reply #20 on: August 31, 2011, 09:36:11 pm »
Reinstall and make sure the checkbox for contrib plugins is checked.

Reinstalled it and made sure the RegEx testbed plugin was checked. I'll try it out.

Re-install doesn't fix the goto error line thingy.
Why should it.

Rename the path, so it contains no special characters (the ampersand in your case) and it will work again.
Alternatively you can add the ampersand to the output parsing regexes for warnings and errors in "Settings -> Compiler and debugger... -> Other settings -> Advanced options... -> Output parsing".

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Build messages settings and Find/Replace tool
« Reply #21 on: August 31, 2011, 09:50:45 pm »
Jens: why don't we add them to head svn, too?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Build messages settings and Find/Replace tool
« Reply #22 on: August 31, 2011, 10:52:07 pm »
Jens: why don't we add them to head svn, too?
Committed !
I also changed A-Za-z0-9 to [:alnum:], so all alphanumeric characters can be parsed, not only ascii-characters.
Works fine on linux and windows 7, tested with german umlauts and french accents.

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Build messages settings and Find/Replace tool
« Reply #23 on: September 04, 2011, 11:32:44 pm »
Why should it.

Rename the path, so it contains no special characters (the ampersand in your case) and it will work again.
Alternatively you can add the ampersand to the output parsing regexes for warnings and errors in "Settings -> Compiler and debugger... -> Other settings -> Advanced options... -> Output parsing".


Thank you. Problem fixed. Sorry I didn't reply sooner as I was working on researching the GIF specification.